有没有办法在MySql中模拟GROUP BY WITH CUBE?
MySql 支持 GROUP BY WITH ROLLUP ,它将返回 group by 中 n 列的最后 x 的聚合,但不支持 GROUP BY WITH CUBE 来获取 n 列的所有组合并获取聚合。
我可以通过执行 GROUP BY AND ROLLUP 查询的联合来模拟这一点,但 MySql 多次具体化我的子查询。我在大型子查询上使用 group by,所以这是次优的。有没有办法在没有临时表的情况下解决这个问题?
MySql supports GROUP BY WITH ROLLUP which will return aggregates for the last 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
简短的回答:不。
详细的回答:您可以安装一个支持 GROUP BY WITH CUBE 的开源数据仓库,该数据仓库使用 Mysql 作为存储引擎,例如 Pentaho。
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.
使用 Roll up 是用您可视化的面和角构建立方体的解决方案。在本例中,我假设您使用虚拟 ROLAP。如果你有足够的内存。我建议使用内存引擎来具体化立方体,并根据需要使用钻取和切片操作或立方体操作。
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.