Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.
Shade in the A or B circle for each question.
Draw a line connecting each item on the left to its match on the right.
| Left column | Right column | |
|---|---|---|
| 1GROUP BY house HAVING COUNT(*) > 2 | ASELECT house, COUNT(*) FROM students WHERE yearLevel = 7 GROUP BY house; | |
| 2HAVING AVG(mark) >= 75 | BKeeps only the groups whose average mark is 75 or higher. | |
| 3WHERE filters individual rows before grouping, so it can remove Year 7 students before they are counted. | CHAVING is placed before GROUP BY. It must come after GROUP BY, as it filters the groups that GROUP BY creates. | |
| 4Clause order: HAVING comes after GROUP BY and before ORDER BY. | DWHERE cannot use an aggregate like COUNT(*) because it filters rows before groups exist. The condition should be in HAVING after GROUP BY. | |
| 5SELECT house, COUNT(*) FROM students WHERE COUNT(*) > 2 GROUP BY house; | ESELECT house, SUM(points) FROM students GROUP BY house HAVING SUM(points) > 200 ORDER BY house; | |
| 6SELECT house, COUNT(*) FROM students HAVING COUNT(*) > 2 GROUP BY house; | FGroups students by house, then keeps only the houses that have more than 2 students. |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
HAVING — Filters groups after GROUP BY using a condition on an aggregate, e.g. HAVING COUNT(*) > 2. WHERE filters rows before grouping. HAVING comes after GROUP BY.SELECT house, COUNT(*) FROM students
GROUP BY house
HAVING COUNT(*) > 2;SELECT house, COUNT(*) FROM students
GROUP BY house
HAVING COUNT(*) > 2;SELECT house, COUNT(*) FROM students
WHERE yearLevel = 8
GROUP BY house;SELECT category, COUNT(*) FROM products
GROUP BY category
HAVING COUNT(*) > 2;SELECT subjectId, AVG(mark) FROM results
GROUP BY subjectId
HAVING AVG(mark) > 70;