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(*) > 3 | AKeeps only the houses that have more than 3 students | |
| 2GROUP BY subjectId HAVING AVG(mark) >= 70 | BSELECT subjectId, AVG(mark) FROM results GROUP BY subjectId HAVING AVG(mark) > 75; | |
| 3WHERE filters individual rows before grouping, so it is used for plain column conditions | CAn aggregate such as COUNT(*) is used in WHERE. WHERE runs before grouping, so move the condition to HAVING after GROUP BY. | |
| 4HAVING filters whole groups after GROUP BY, so it can use an aggregate such as AVG | DKeeps only the subjects whose average mark is 70 or more | |
| 5SELECT house, COUNT(*) FROM students WHERE COUNT(*) > 3 GROUP BY house; | EHAVING is placed before GROUP BY. The clause order is wrong: HAVING must come after GROUP BY. | |
| 6SELECT house, COUNT(*) FROM students HAVING COUNT(*) > 3 GROUP BY house; | FSELECT house, COUNT(*) FROM students WHERE yearLevel = 7 GROUP BY house; |
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 an aggregate condition, such as HAVING COUNT(*) > 3. WHERE filters rows before grouping.SELECT house, COUNT(*) FROM students
GROUP BY house
HAVING COUNT(*) > 2;SELECT category, AVG(price) FROM products
GROUP BY category
HAVING AVG(price) > 5;SELECT house, COUNT(*) FROM students
WHERE yearLevel = 8
GROUP BY house;SELECT studentId, AVG(mark) FROM results
GROUP BY studentId
HAVING AVG(mark) >= 75;SELECT house, SUM(points) FROM students
GROUP BY house
HAVING SUM(points) > 200;