Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Second Highest Marks SQL

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

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

TraceLink Opus tracks student results for internal onboarding assessments. Write a PostgreSQL query to find the students who achieved the second highest distinct mark on the TraceLink Opus Onboarding assessment.

Requirements

  1. Consider only active students and non-null marks for the specified assessment.
  2. Treat tied marks as one rank, so every student sharing the second highest distinct mark must be returned.
  3. Return student_id, student_name, and marks, ordered by marks descending and then student name ascending.

Schema

students
ColumnTypeDescription
student_idPKINTUnique student identifier
student_nameVARCHAR(100)Student's full name
is_activeBOOLEANWhether the student is currently active
assessment_scores
ColumnTypeDescription
score_idPKINTUnique score identifier
student_idINTReferences students.student_id
assessment_nameVARCHAR(150)Name of the assessment
marksINTMarks earned, from 0 to 100
Tablesstudentsassessment_scores
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results