开发者

Is there a way to simulate GROUP BY WITH CUBE in MySql?

开发者 https://www.devze.com 2023-03-29 01:42 出处:网络
MySql supports GROUP BY WITH ROLLUP which will return aggregates for the l开发者_运维技巧ast x of the n columns in the group by but does not support GROUP BY WITH CUBE to take all combinations of the

MySql supports GROUP BY WITH ROLLUP which will return aggregates for the l开发者_运维技巧ast x of the n columns in the group by but does not support GROUP BY WITH CUBE to take all combinations of the n columns and take aggregates.

I can simulate this by doing unions of GROUP BY WITH ROLLUP queries, but MySql is materializing my subquery multiple times. I am using a group by on a large subquery, so this is suboptimal. Is there a way to solve this without temporary tables?


Short answer: No.

Long answer: You may install an open source data warehouse with GROUP BY WITH CUBE support which is using Mysql as a storage engine, such as Pentaho.


The use of Roll up is the solution to build the cube with the faces and corners that you visualize. In this case I assume you use virtual ROLAP. If you have enough memory. I propose to use the memory engine to materialize the cube, and make use of drill and slice operations or cube operations as needed.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号