Grade 12 · Databases & SQL · SQL lab · about 18 minutes
Open this task in the Delphi workspace →
Aggregate functions squash many rows into one answer:
| Function | Answers |
|---|---|
| COUNT(*) | how many rows? |
| SUM(field) | total |
| AVG(field) | average |
| MAX(field) / MIN(field) | highest / lowest |
Give the answer column a decent heading with AS:
SELECT COUNT(*) AS Total
FROM tblLearners
WHERE Grade = 12
GROUP BY splits the rows into groups first and aggregates each group — one result row per group:
SELECT Grade, AVG(ITMark) AS AvgMark
FROM tblLearners
GROUP BY Grade
Golden rule: every field in the SELECT that is not inside an aggregate must appear in the GROUP BY. (Break the rule here and read the error — it is the same one Access gives.)