使用 CUBE 查看所有聚合
CUBE 运算符会对所有组合进行交叉聚合,可能产生大量行。该运算符最适用于非层级型数据,既关注各维度的独立聚合,也关注它们的组合聚合。
在本练习中,您希望统计 IncidentRollup 表中的安全事件总数,但不按严格层级来做。相反,您将聚合若干彼此无关的属性。
本练习是课程的一部分
SQL Server 中的时间序列分析
交互式实操练习
通过完成这段示例代码来试试这个练习。
SELECT
-- Use the ORDER BY clause as a guide for these columns
-- Don't forget that comma after the third column if you
-- copy from the ORDER BY clause!
ir.___,
c.___,
c.___,
SUM(ir.NumberOfIncidents) AS NumberOfIncidents
FROM dbo.IncidentRollup ir
INNER JOIN dbo.Calendar c
ON ir.IncidentDate = c.Date
WHERE
ir.IncidentTypeID IN (3, 4)
GROUP BY
-- GROUP BY should include all non-aggregated columns
ir.___,
c.___,
c.___
-- Fill in your grouping operator
WITH ___
ORDER BY
ir.IncidentTypeID,
c.CalendarQuarterName,
c.WeekOfMonth;