聚合窗口函数
SQL 提供了多种聚合窗口函数可用。本练习将演示如何在同一个窗口上计算多个聚合。
这次使用的窗口是整个数据集,也就是说 OVER() 子句将保持为空。
本练习是课程的一部分
SQL Server 中的时间序列分析
练习说明
- 为结果集中每一列填写正确的聚合函数。
交互式实操练习
通过完成这段示例代码来试试这个练习。
SELECT
ir.IncidentDate,
ir.NumberOfIncidents,
-- Fill in the correct aggregate functions
-- You do not need to fill in the OVER clause
___(ir.NumberOfIncidents) OVER () AS SumOfIncidents,
___(ir.NumberOfIncidents) OVER () AS LowestNumberOfIncidents,
___(ir.NumberOfIncidents) OVER () AS HighestNumberOfIncidents,
___(ir.NumberOfIncidents) OVER () AS CountOfIncidents
FROM dbo.IncidentRollup ir
WHERE
ir.IncidentDate BETWEEN '2019-07-01' AND '2019-07-31'
AND ir.IncidentTypeID = 3;