ITPEC FE Morning October 2023 Question 28

Source exam: ITPEC FE Morning October 2023Topic: Databases

ITPEC FE Morning October 2023 — Question 28 of 80

SQL GROUP BY + HAVING — filter groups by aggregate condition.

Goal: get each student's average score, but only where that average is 80 or higher.

  • GROUP BY StudentNumber — groups rows per student
  • HAVING AVG(Score) >= 80 — filters after aggregation

Full query:
SELECT StudentNumber, AVG(Score) FROM Score GROUP BY StudentNumber HAVING AVG(Score) >= 80

WHERE vs HAVING:
- WHERE filters individual rows before grouping

- HAVING filters groups after aggregation

Why not others:
- (b) WHERE Score >= 80 — excludes rows before averaging, distorting the result

- (c) GROUP BY Subject — wrong grouping key (need per-student, not per-subject)

- (d) GROUP BY Subject WHERE Score >= 80 — wrong grouping key and wrong filter type

AI-generated — may contain errors

The original exam layout is preserved in the image so diagrams, formulas, tables, and code remain accurate.

This question comes from an official ITPEC past paper. ITPEC Practice is an independent study tool and is not affiliated with ITPEC. See the official FE past-paper collection or Report an issue.