เริ่มต้นใช้งานเริ่มต้นใช้งานได้ฟรี

Aggregate window functions

มี aggregate window functions หลายฟังก์ชันให้ใช้งาน ในแบบฝึกหัดนี้ เราจะฝึกใช้ aggregate หลายรายการบน window เดียวกัน

ครั้งนี้ window ของเราครอบคลุมชุดข้อมูลทั้งหมด ซึ่งหมายความว่า clause OVER() จะเว้นว่างไว้

แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร

การวิเคราะห์อนุกรมเวลาใน SQL Server

ดูคอร์ส

คำแนะนำการฝึกหัด

  • ใส่ฟังก์ชัน aggregate ที่ถูกต้องสำหรับแต่ละคอลัมน์ในผลลัพธ์

แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ

ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์

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;
แก้ไขและรันโค้ด