多维数据集和WITH CUBE之间的区别

时间:2018-08-06 14:47:02

标签: sql tsql cube rolap

我在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()是“企业版”的功能

2 个答案:

答案 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声明外,在这种情况下-两者都做完全相同的事情