All problems

Who's Below Their Major's Average GPA?

mediumSQLSubqueries

Student support at Fairhaven University runs a light-touch check-in each term. The point is not to catch students who are failing — the registrar already has that list — but to notice the ones drifting behind the people they sit next to, before it becomes a real problem.

That makes the comparison a local one. A 3.4 is comfortable in a cohort averaging 3.1 and a warning sign in one averaging 3.85, so a single university-wide threshold would flag the wrong students in both directions. Every student has to be measured against their own subject, and no column holds a subject's typical GPA — it has to come out of the same five rows you are reading.

students — one row per student. gpa is the grade point average on a 0-4 scale. major is the subject they are reading.

id name major gpa
1 Nora Fischer Computer Science 3.8
2 Omar Haddad Statistics 3.4
3 Petra Novakova Computer Science 3.9
4 Quinn Walsh Mathematics 3.1
5 Ravi Shah Statistics 3.6

The table already exists in the database — there is nothing to create or load.

Task: Write a query returning a single column, name, holding every student whose gpa is strictly below the average gpa of their own major. A student sitting exactly on their subject's average is not below it and does not appear. The only student in a one-person subject can never be below their own average, so that subject contributes nobody. Hand the names back in alphabetical order.

Example output — shape only, on invented names.

name
Bram Visser
Lucia Ferreira

Sign in to solve this problem

Reading problems is free for everyone — solving them (Run, Submit, and tracking what you've solved) needs an account.

Sign in

Discussion

Sign in to join the discussion — reading is open to everyone.

Loading comments…