Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

SQL for Second Highest Marks

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

Your question is SQL for Second Highest Marks. 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

Yum! Brands uses Yum Academy assessments to monitor employee readiness across its restaurant brands. Write a PostgreSQL query to identify the student or students with the second-highest marks in the Restaurant Operations Assessment.

Requirements

  1. Join students to their assessment scores and the assessment definition.
  2. Rank distinct non-null marks from highest to lowest using a window function.
  3. Return every student whose marks are the second-highest distinct score, ordered by student name.

Schema

students
ColumnTypeDescription
student_idPKINTUnique student identifier
student_nameVARCHAR(100)Student's full name
brandVARCHAR(50)Yum! Brands restaurant brand
assessments
ColumnTypeDescription
assessment_idPKINTUnique assessment identifier
assessment_nameVARCHAR(150)Assessment title
assessment_scores
ColumnTypeDescription
score_idPKINTUnique score record
student_idINTStudent receiving the score
assessment_idINTAssessment being scored
marksINTAssessment marks from 0 to 100
Tablesstudentsassessmentsassessment_scores
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results