Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Get started
Top Student Per Subject SQL
00:00
5 left

Top Student Per Subject SQL

EasySQL · PostgreSQL

Problem

Affirm's quantitative analytics team is reviewing subject-level assessment results for analysts supporting Affirm financing decisions. Write a PostgreSQL query that identifies the top student or students in each subject for the current exam term.

Requirements

  1. Restrict results to the 2026-Spring exam term and exclude records where marks is NULL.
  2. Rank students independently within each subject using their marks in descending order.
  3. Return every student tied for the highest mark, along with the subject name, student ID, student name, and mark.
  4. Sort the final results alphabetically by subject name and then by student ID.

Schema

students
ColumnTypeDescription
student_idPKINTUnique student identifier
student_nameVARCHAR(100)Student's full name
subjects
ColumnTypeDescription
subject_idPKINTUnique subject identifier
subject_nameVARCHAR(100)Subject name
exam_scores
ColumnTypeDescription
score_idPKINTUnique score record identifier
student_idINTReferences students.student_id
subject_idINTReferences subjects.subject_id
marksINTMarks earned in the assessment
exam_termVARCHAR(30)Assessment term
Tablesstudentssubjectsexam_scores
Interviewer

Your question is Top Student Per Subject SQL. Start with the requirements and the three tables in the Question tab.

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.
CodePostgreSQL
Sign up free to run your codeLog inLn 1
Run your query to see results here.