Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Average Grade Per Subject

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

Your question is Average Grade Per Subject. Start with the requirements and the three 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

Adobe Learning Manager stores student assessments by subject. Write a PostgreSQL query that reports the average grade for every subject, considering only grades submitted by active students.

Requirements

  1. Return every subject, including subjects with no qualifying grades.
  2. Exclude inactive students and NULL grade values from the average.
  3. Return the average grade rounded to two decimal places and the count of graded submissions.
  4. Sort the results alphabetically by subject name.

Schema

students
ColumnTypeDescription
student_idPKINTUnique student identifier
student_nameVARCHAR(100)Student's display name
is_activeBOOLEANWhether the student is currently active
subjects
ColumnTypeDescription
subject_idPKINTUnique subject identifier
subject_nameVARCHAR(100)Subject name
grades
ColumnTypeDescription
grade_idPKINTUnique grade record identifier
student_idINTReferences students.student_id
subject_idINTReferences subjects.subject_id
scoreNUMERIC(5,2)Submitted grade
Tablesstudentssubjectsgrades
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results