S4 Term 2 | ICT: SQL Queries – Tutor Lesson Plan | 45-minute flow, teaching script, common errors, practice with answers
- 2026-12-01
Lesson prep guide · S4 Term 2 ICT
Students can write SELECT and WHERE, yet they drop SUM into WHERE the moment a total is asked for. This lesson uses nine bookings to show that a query runs in a fixed order and aggregates belong in HAVING.
01 Prior knowledge check (first 3 minutes)
If any item below fails, fix it first, or this lesson stalls:
| Skill | Quick check | Pass standard |
|---|---|---|
| Adding | Fees of 480, 520 and 560 | 1560 |
| Averaging | 4680 over 9 bookings | 520 |
| Filtering | How many of the 9 bookings belong to class 4A | 6 |
02 Lesson flow (45 minutes)
| Time | Stage | Tutor does | Student does |
|---|---|---|---|
| 0–6 min | Opening: SUM inside WHERE | Show the broken query and ask why it fails | Spot the WHERE clause |
| 6–18 min | SELECT and WHERE | Three students in 4A; a course filter returns 3 rows | Predict the row count first |
| 18–28 min | GROUP BY and HAVING | Six groups, HAVING leaves two at 1560 and 1040 | Write one HAVING clause |
| 28–38 min | Joining tables | Students joined to Enrolments gives 6 rows for 4A | Count the joined rows |
| 38–42 min | ORDER BY and LIMIT | Descending order starts 1560, 1040, 560 | Write the sorted order |
| 42–45 min | Exit check | Collect three answers and sort order, aggregate and join errors | Work without notes |
03 Teaching script (read it aloud)
Act one: a query runs in a fixed order
Students restate: WHERE runs before grouping and HAVING after it, so aggregates belong in HAVING.
Act two: aggregates and grouping
Students restate: an aggregate collects rows before it returns a value, so group conditions use HAVING.
Act three: JOIN puts the tables back together
Students restate: every JOIN needs ON, or the result is the Cartesian product of both tables.
04 Question types and steps
| Type | Example | Steps | Answer |
|---|---|---|---|
| Basic query | WHERE class = ‘4A’ | WHERE filters rows, SELECT picks columns | Three students and 6 bookings |
| Aggregate | 9 bookings | SUM, AVG and COUNT collapse rows | A total of 4680 and a mean of 520 |
| Group and filter | GROUP BY student_id | Group first, then test the total in HAVING | Two students at 1560 and 1040 |
| Join | Students JOIN Enrolments ON student_id | Join, then filter by class | 6 rows for 4A |
One query over nine bookings finds the students in class 4A whose total exceeds 1000. FROM joins Students to Enrolments for nine rows, WHERE keeps the six rows of 4A, GROUP BY makes six groups, HAVING drops the four groups below 1000, SELECT returns name and total, ORDER BY sorts high to low and LIMIT keeps two rows, giving 1560 for Chan Tai Man and 1040 for Cheung Ka Ho. Get the order wrong and an aggregate in WHERE fails outright.
05 Three independent practice questions
| Question | Answer | What to observe |
|---|---|---|
| Write the query for the names of class 4A and state the row count. | SELECT name FROM Students WHERE class = ‘4A’; three rows | Watch for HAVING in place of WHERE and for missing quotes |
| Write each student total, keeping only those above 1000, highest first. | SELECT student_id, SUM(paid) FROM Enrolments GROUP BY student_id HAVING SUM(paid) >= 1000 ORDER BY SUM(paid) DESC; giving 1560 and 1040 | Watch for an aggregate in WHERE and a missing ORDER BY |
| How many rows result if Students joins Enrolments with no ON clause? | 6 times 9, or 54, a Cartesian product | Watch for the reason: every row paired with every row |
06 Common errors and correction lines
| Error | Student usually writes | Tutor says |
|---|---|---|
| SUM in WHERE | WHERE SUM(paid) >= 1000 | “WHERE runs before grouping, when no total exists; put the total in HAVING.” |
| Missing GROUP BY | SELECT student_id, SUM(paid) FROM Enrolments | “An aggregate per student needs GROUP BY student_id.” |
| JOIN without ON | FROM Students JOIN Enrolments | “Without ON every row pairs with every row, six times nine is 54 rows, all wrong.” |
| Wrong sort direction | ORDER BY SUM(paid) | “Highest first needs DESC; without it the order runs low to high.” |
07 Homework (paper and question numbers)
- S4 ICT paper, section C, question 9(b): build the three tables first Part (b) yields the student, course and order tables that a join starts from
- S5 ICT paper, question 1, part 1: the top three students of 5A with names and scores Part 1 tests WHERE, ORDER BY DESC and LIMIT 3, the syntax of act one
- S5 ICT paper, question 1, part 2: each student average, keeping 60 and above Part 2 tests GROUP BY, AVG and HAVING, which is act two
08 Exit check (last 3 minutes)
| Question | Answer | Verdict |
|---|---|---|
| Which runs first, WHERE or HAVING? | WHERE, before grouping; HAVING after it | The reverse means act one again |
| What are the total and mean of the 9 bookings? | 4680 and 520 | Wrong numbers means act two again |
| How many rows from a join with no ON? | 54, a Cartesian product | Nine means joins are missing |
09 Tutor FAQ
Which year is this page for?
S4 Term 2, the SQL unit of local secondary ICT; S5 adds subqueries, LEFT JOIN and three-table joins.
Is 45 minutes enough for five clauses?
Yes: twelve minutes on SELECT and WHERE, ten on GROUP BY and HAVING, ten on joins, and the rest on sorting, practice and the exit check.
Is there a matching worksheet?
Yes. The homework links to question 1, parts 1 and 2 of the S5 ICT paper, with full answers.
Find a tutor freeTutor sign-up →
©2026 TutorZone · www.tutorzone.com.hk · Terms of use · All rights reserved. Original TutorZone material for personal study and teaching only; not for resale or republication.



