All problems

Students Above Their Major's Average GPA

hardSQLWindow FunctionsSubqueries

Fairhaven University is drawing up this year's departmental honours list, and the registrar has already thrown out the obvious rule. A flat cutoff — everyone above 3.7, say — mostly rewards whichever department grades most generously, and in a strict department it can leave the honours list empty. What the faculty want to recognise is a student who is ahead of the field they are actually competing in: the other students on their own major.

students — one row per enrolled student. gpa is on a 4.0 scale.

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 tables are already created and filled in the editor — there is nothing to read from input.

Task: Write a query that returns the name, major and gpa of every student whose GPA is strictly above the average GPA of all students on that same major. Strictly above is the rule that matters: a student sitting exactly on their major's average is left out, and as a consequence a major with only one student never contributes anybody, because that student is the average. Hand the qualifying students back in alphabetical name sequence.

Example output — shape only, on invented students and subjects.

name major gpa
Kofi Mensah Economics 3.55
Tara Villalobos Physics 3.72

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…