MulaiMulai sekarang secara gratis

Creating grouped aggregations

You can calculate statistics for each group using GROUP BY. For example, you can calculate the maximum value for each state using the following query:

SELECT State, MAX(DurationSeconds)
FROM Incidents
GROUP BY State

To filter even further, for example, to find the values for states where the maximum value is greater than 10, you can use the HAVING clause.

Latihan ini adalah bagian dari kursus

Intermediate SQL Server

Lihat Kursus

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

-- Calculate the aggregations by Shape
SELECT ___,
       AVG(DurationSeconds) AS Average, 
       MIN(DurationSeconds) AS Minimum, 
       MAX(DurationSeconds) AS Maximum
FROM Incidents
___
Edit dan Jalankan Kode