Aggregate Functions: CIS 331: Introduction To Database Systems
Aggregate Functions: CIS 331: Introduction To Database Systems
Topics:
ORDER BY, ASC, DESC Aggregate functions COUNT SUM MIN MAX AVG GROUP BY and HAVING
Vladimir Vacic, Temple University
2
Ascending (ASC) order is the default, so you do not have to specify it explicitly:
SELECT first_name, middle_name, last_name FROM professors ORDER BY last_name ;
Or a students GPA:
SELECT student, AVG(grade) FROM students_classes GROUP BY student ORDER BY AVG(grade) ;
Having
Get a list of students who have a GPA over 3.5: SELECT student, AVG(grade) FROM students_classes GROUP BY student HAVING AVG(grade) > 3.5 ; Observe the HAVING clause: it is similar to WHERE, except that you can use aggregate expressions as conditions.