Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

SQL Above Class Average

EasySQL · PostgreSQL00:00
Practice interviewer
In session
5 left
00:00

Your question is SQL Above Class Average. Start with the requirements and the two tables on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Ericsson is reviewing results from an internal data engineering class. Write a PostgreSQL query to identify trainees whose grade is strictly higher than the class average.

The class average must be calculated from all non-NULL grades in student_grades. Include only students with a recorded grade above that average.

Requirements

  1. Calculate the overall class average using AVG, allowing PostgreSQL to ignore NULL grades.
  2. Return the student ID, student name, grade, and rounded class average.
  3. Exclude students whose grade is NULL or equal to the class average.
  4. Sort the results by grade descending, then student ID ascending for ties.

Schema

students
ColumnTypeDescription
student_idPKINTEGERUnique trainee identifier
student_nameVARCHAR(100)Trainee's full name
student_grades
ColumnTypeDescription
student_idPKINTEGERTrainee identifier referencing students.student_id
gradeNUMERIC(5,2)Class grade from 0 to 100
Tablesstudentsstudent_grades
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results