All problems

Average GPA by Major

easySQLGroupByAggregation

The registrar at Fairhaven University publishes a one-page summary each year showing how students in each major are doing. You have been handed the student table and asked for the figures behind that page.

The majors are wildly uneven — one has a single student on the books — so these numbers are going to be fragile, and the registrar knows it. The page wants one figure per major regardless, printed to two decimal places so the column lines up on the page.

students — one row per student. gpa is on the usual 0–4 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 table already exists in the database — there is nothing to create or load.

Task: Write a query returning two columns, major and avg_gpa, with one row per major and the mean GPA rounded to 2 decimals. Rows come back in alphabetical order of major.

Example output — shape only, on invented majors. A mean that lands on one decimal prints with one, not padded out to two.

major avg_gpa
Economics 3.25
Linguistics 2.9
Physics 3.4

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…