Aggregate Functions
Aggregate Functions
Aggregates
2
Aggregates
Count the number of courses taught in S2000
SELECT COUNT (T.CrsCode)
FROM Teaching T
WHERE T.Semester = ‘S2000’
But if multiple sections of same course
are taught, use:
SELECT COUNT (DISTINCT T.CrsCode)
FROM Teaching T
WHERE T.Semester = ‘S2000’
3
Aggregates: Proper and Improper
Usage
SELECT COUNT (T.CrsCode), T. ProfId
…… --makes no sense (in the absence of
GROUP BY clause)
5
GROUP BY - Example
Transcript
Attributes:
-student’s Id
1234 1234 3.3 4 -avg grade
1234
1234 -number of courses
1234
7
Evaluation of GroupBy with Having
8
Example
9
ORDER BY Clause
11