/en-tutor-prep-s4-term2-ict-sql/
/en-tutor-prep-s4-term2-ict-sql/
General Inquiry: info@TutorZone.com.hk
Office Hours: Monday to Saturday - 9:00 AM to 6:00 PM
WhatsApp Monday to Sunday - 24 hours
Hotline: +852 6828 1809
Instant Support: +852 9061 3106

S4 Term 2 | ICT: SQL Queries – Tutor Lesson Plan | 45-minute flow, teaching script, common errors, practice with answers

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.

Lesson objectives Students can (1) write SELECT, WHERE, ORDER BY and LIMIT queries and predict the row count; (2) group with GROUP BY and filter groups with HAVING, and say why WHERE cannot hold an aggregate; (3) join two tables on key and foreign key and count the joined rows.

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 read SQL from left to right and put SUM in WHERE as soon as a total is mentioned. The real order is FROM for the tables, WHERE row by row, GROUP BY, HAVING for the groups, SELECT for the columns, ORDER BY and LIMIT. WHERE runs before grouping, when no total exists yet, so an aggregate there always fails. With 9 bookings, FROM gives 9 rows, WHERE keeps the 6 rows of 4A, GROUP BY makes six groups, HAVING keeps the two groups above 1000, SELECT returns the student and the total, ORDER BY sorts descending and LIMIT keeps two rows.

Students restate: WHERE runs before grouping and HAVING after it, so aggregates belong in HAVING.

Act two: aggregates and grouping

SUM, AVG, COUNT, MAX and MIN are aggregates that turn many rows into one value. The whole table of 9 bookings totals 4680 with a mean of 520. Grouped by student, one student with three bookings pays 1560, another with two pays 1040, and the remaining four pay between 480 and 560. Grouped by class, 4A pays 3080, or 65.8 per cent of the total, against 1600 for 4B, and grouped by course the totals are 1440, 1560 and 1680, which add up to 4680.

Most common misconception: that WHERE can filter a total after grouping. A condition on a group always goes in HAVING, or the query fails or filters rows instead.

Students restate: an aggregate collects rows before it returns a value, so group conditions use HAVING.

Act three: JOIN puts the tables back together

Once the tables are split, a query joins them again. Students joins Enrolments on student_id and Enrolments joins Courses on course_id, and WHERE decides the rows: the whole table is 9 rows and class 4A leaves 6. Forget the ON condition and the result becomes a Cartesian product of 6 students times 9 bookings, or 54 rows, which is obvious at a glance. An INNER JOIN drops students with no bookings, and keeping them needs a LEFT JOIN, which is left for S5; in S4 the goal is to predict the joined row count.

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
Query order: FROM, WHERE, GROUP BY, HAVING, SELECT, ORDER BY, LIMITStudentsIDNameClass1Chan Tai Man4A3Wong Mei Yee4B4Cheung Ka Ho4AEnrolmentsIDStudentCourseFee11101480311035606410356074101480WHERE class = 4AFROM9 rowsWHERE6 rows in 4AGROUP BY6 groupsHAVINGkeeps 2SELECT3 columnsORDER BY1560 firstLIMIT2 rowsResult: Chan Tai Man 1560, Cheung Ka Ho 1040; class 4A totals 3080 of 4680, or 65.8 per centWHERE cannot test SUM(paid): aggregates belong in HAVING, because WHERE runs before grouping

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.

Sanity check (must teach):9 bookings total 4680 with a mean of 520. Grouped by student there are six groups, and only two exceed 1000, at 1560 and 1040. Class 4A pays 3080 against 1600 for 4B, or 65.8 per cent. By course the totals are 1440, 1560 and 1680, which add to 4680. Without ON the Cartesian product is 6 times 9, or 54 rows.

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)

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.

Take this guide with you

Reading the full guide is free. Downloading the print version, printing it for students, or taking a whole-level pack needs a tutor account (free).

Registered tutors also get:

Register as a tutor — freeAlready registered? Log in

Join as a tutor or coach — academic, music, sports, arts, STEM. Free to register. See how it works →