SQL Boy
TutorialsPlayground

Format & Validate

SQL FormatterSQL MinifierSyntax Validator

Convert

JSON to SQLCSV to SQLSQL to JSONRegex to SQLExcel to SQLSQL Dialect Convertersoon

Visualize

ER Diagram GeneratorSQL Schema Diff

Generate

SQL Mock Data Generator

Analyze

SQL Query ExplainerSQL Query Analyzer

Workflow hubs

FormattingConversionSchemaAnalysis
View all tools
Daily ChallengeInterviewsCheat SheetBlog

© 2026 SQL Boy. Built for developers.

ContactPrivacyTermsAI Usage PolicyEditorial StandardsAboutRSS Feed

New conversation

What can I help with?

Ask about this page, get a hint on a challenge, or explore SQL concepts.

I know what's on this page and can give answers grounded in SQL Boy content.

Current page

Rank Scores

/challenges/rank-scores

Usage status will load after login
SQL Boy
TutorialsPlayground

Format & Validate

SQL FormatterSQL MinifierSyntax Validator

Convert

JSON to SQLCSV to SQLSQL to JSONRegex to SQLExcel to SQLSQL Dialect Convertersoon

Visualize

ER Diagram GeneratorSQL Schema Diff

Generate

SQL Mock Data Generator

Analyze

SQL Query ExplainerSQL Query Analyzer

Workflow hubs

FormattingConversionSchemaAnalysis
View all tools
Daily ChallengeInterviewsCheat SheetBlog
SQL Challenges/Rank Scores
Challenge DetailMediumReviewed 2026-04-20

Rank Scores

Rank scores. If there is a tie between two scores, both should have the same ranking. Note that after a tie, the next ranking number should be the next consecutive integer value. In other words, there should be no holes between ranks.

Window FunctionsAggregation

This challenge now meets the current minimum standard for sitemap inclusion and independent indexing.

2025-12-20Medium

Rank Scores

Rank scores. If there is a tie between two scores, both should have the same ranking. Note that after a tie, the next ranking number should be the next consecutive integer value. In other words, there should be no holes between ranks.

Available Tables:
SQL Editor
Loading...

What This Challenge Is Testing

This problem is the cleanest introduction to the difference between RANK, DENSE_RANK, and ROW_NUMBER. That distinction matters any time you build leaderboards, tier customers, or rank products where duplicate metric values are common.

Topic Tags

Window FunctionsAnalytics

Schema At A Glance

scores
idscore

Solution Approaches

01

DENSE_RANK over descending scores

SELECT
  score,
  DENSE_RANK() OVER (ORDER BY score DESC) AS rank
FROM scores

DENSE_RANK is purpose-built for this requirement. Equal scores share the same rank, and the next distinct score gets the next consecutive rank value with no gaps.

02

Distinct scores first, then join back

WITH ranked_values AS (
  SELECT
    score,
    DENSE_RANK() OVER (ORDER BY score DESC) AS rank
  FROM (
    SELECT DISTINCT score
    FROM scores
  ) distinct_scores
)
SELECT
  s.score,
  r.rank
FROM scores s
JOIN ranked_values r
  ON s.score = r.score

This version makes the value-tier logic explicit by ranking only distinct score values first. It is longer, but it is useful when you want to teach that ranking depends on unique metric levels rather than the physical row count.

Common Pitfalls

Using RANK instead of DENSE_RANK creates holes after ties, which directly violates the requirement. Using ROW_NUMBER is even worse because tied scores get different ranks, turning a value-tier problem into a row-order problem.

Frequently Asked Questions

How is DENSE_RANK different from RANK?

Both give tied values the same rank, but RANK leaves gaps after ties while DENSE_RANK does not. This challenge explicitly says there should be no holes, so DENSE_RANK is the correct choice.

Should I add ORDER BY score DESC or ASC?

Use DESC because the highest score should receive rank 1. Ordering ASC would reverse the leaderboard and rank the smallest score first.

Concept Guides

Use these guides when you want the fuller explanation behind the SQL pattern this challenge is testing.

Understanding SQL Window Functions: A Visual Guide

Master ROW_NUMBER, RANK, and running totals with interactive visualizations. See exactly how window functions process your data row by row.

Ranking Data with SQL: RANK, DENSE_RANK, and ROW_NUMBER Explained

Building leaderboards, finding top performers, or paginating results? Master the three SQL ranking functions and understand exactly when to use each one.

Mastering SQL LEAD and LAG Functions for Row Comparisons

Need to compare a row with its previous or next row? Learn how SQL's LEAD and LAG window functions let you access neighboring rows without complex self-joins.

Topic Hubs

If this problem exposed a deeper weakness, use a topic hub to move through a curated cluster instead of random article hopping.

Advanced SQL

Advanced query patterns

Use this path when you are moving beyond beginner SELECT queries into CTEs, window functions, and conditional logic.

Practice Path

If you want the rotating practice flow, open this same question from the daily stream. If you want interview-style packaging, continue into the interview pool after this rep.

Back to ChallengesOpen In DailyBrowse Interviews

Related Challenges

Second Highest SalaryMedium

Find the second distinct highest salary without accidentally returning the same maximum twice.

Rising TemperatureMedium

Compare each weather row with the previous day and return only the IDs where temperature increased day over day.

Last Person to Fit in the BusMedium

Use a running total to find the last passenger whose cumulative weight still stays under the bus limit.

© 2026 SQL Boy. Built for developers.

ContactPrivacyTermsAI Usage PolicyEditorial StandardsAboutRSS Feed