InterviewPrepKit

Home / SQL / Window Functions

RANK vs DENSE_RANK on Tied Scores

medium 00:00
Solving tips
  • RANK leaves gaps after ties (1,1,3,...); DENSE_RANK does not (1,1,2,...) — pick based on whether skipped positions matter.
  • Ties are defined purely by the ORDER BY expression of the window; two rows tie only if those values are equal.
  • Neither function needs PARTITION BY unless you want the ranking to restart per group.

You have exam scores with several ties. Show, side by side, how RANK and DENSE_RANK number the tied rows differently.

Schema

CREATE TABLE exam_scores (
    student TEXT,
    score   INT
);
studentscore
Ann95
Bob88
Cara95
Dan88
Eve72
Finn88

Task

Rank students by score from highest to lowest. Return student, score, the RANK value as rnk, and the DENSE_RANK value as dense_rnk. Order the output by score descending, then student ascending.

Expected output

studentscorernkdense_rnk
Ann9511
Cara9511
Bob8832
Dan8832
Finn8832
Eve7263

Write your solution, then hit Run tests to check it — or get a mock grade from the AI coach.

The coach remembers this session — revise your code and ask again, and it grades your progress. It gives hints, not the answer.
Report a bug