我在MSSQL中发现两者都存在
SELECT <list of columns>, sum(measure) as measure
FROM fact-table
GROUP BY <list of columns> WITH CUBE
和
SELECT <list of columns>, sum(measure) as measure
FROM fact-table
GROUP BY CUBE (<list of columns>)
我在徘徊有什么区别,因为使用它们,两种语法我都得到相同的结果。
我还记得,至少在2008版中,快速版支持WITH CUBE,而ROLLUP(),CUBE()和GROUPING SETS()是“企业版”的功能
答案 0 :(得分:1)
差异在documentation中说明:
SQL Server和Azure SQL数据库的语法
符合ISO的语法GROUP BY { column-expression | ROLLUP ( <group_by_expression> [ ,...n ] ) | CUBE ( <group_by_expression> [ ,...n ] ) | GROUPING SETS ( <grouping_set> [ ,...n ] ) | () --calculates the grand total } [ ,...n ]
仅用于向后兼容。
SQL Server和Azure SQL数据库的非ISO语法GROUP BY [ ALL ] column-expression [ ,...n ] | column-expression [ ,...n ] [ WITH { CUBE | ROLLUP } ]
和:
Feature SQL Server SQL Server SQL Server 2008 or later Integration Services compatibility level 100 with compatibility level 90 or higher CUBE Not supported Supported Not supported WITH CUBE Supported Supported Supported
答案 1 :(得分:0)
我相信 WITH 关键字在所有情况下都是可选的,除了启动CTE声明外,在这种情况下-两者都做完全相同的事情