Monday, 4 May 2015

Summary Functions in mysql

Summary Functions

SELECT Dept, Level, ROUND(AVG(TotalStudents)) AS Average
FROM 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