LearnStanmorephysics

Grade 12 · Matric Mastery

Aggregates & GROUP BY

Grade 12 · Databases & SQL · SQL lab · about 18 minutes

Open this task in the Delphi workspace →

Aggregate functions squash many rows into one answer:

FunctionAnswers
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.)

About this material

This platform provides original CAPS-aligned practice material and study tools. Content is machine-verified and has not been reviewed by subject specialists. It is not affiliated with or endorsed by the Department of Basic Education. Learners should also use official past papers and consult their teachers where uncertain.