Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Max CGPA by Year and Gender

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

Your question is Max CGPA by Year and Gender. 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

Write an SQL query to find the maximum CGPA per year, broken down by gender.

Use the student and academic record data. Treat records with a missing CGPA as unavailable.

Output

  1. One row per academic year and gender with a non-null CGPA
  2. Columns: year, gender, and max_cgpa
  3. Sort by year ascending, then gender ascending, with missing gender values last

Schema

students
ColumnTypeDescription
student_idPKINTUnique student identifier
student_nameVARCHAR(100)Student's full name
genderVARCHAR(30)Student's gender classification
academic_records
ColumnTypeDescription
record_idPKINTUnique academic record identifier
student_idINTStudent associated with the academic record
academic_yearINTAcademic year represented as a four-digit year
cgpaNUMERIC(3,2)Cumulative grade point average
Tablesstudentsacademic_records
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results