Summary Functions
SELECT Dept, Level, ROUND(AVG(TotalStudents)) AS AverageFROM Classes
GROUP BY Dept, Level WITH ROLLUP;
use of the WITH ROLLUP option in the GROUP BY clause. As a result, averages are provided for the departments as a whole and for all classes added together.
SELECT Dept, Level, SUM(TotalStudents) AS Total
FROM Classes
GROUP BY Dept, Level WITH ROLLUP
----------------------------------------------------------------------------------
SELECT Dept, Level, MIN(TotalStudents) AS Minimum
FROM Classes
GROUP BY Dept, Level WITH ROLLUP;
---------------------------------------------------------------------------------------
SELECT Dept, Level, MAX(TotalStudents) AS Maximum
FROM Classes
GROUP BY Dept, Level WITH ROLLUP;
-----------------------------------------------------------------------------------------
SELECT Dept, Level, COUNT(*) AS NumberClasses
FROM Classes
GROUP BY Dept, Level WITH ROLLUP;
No comments:
Post a Comment