Katkat

Resolve Ties for Top-10 Users in SQL Query

MetaData Scientist · Onsite

Last updated

This question evaluates proficiency in SQL ranking and tie-resolution techniques for generating deterministic top-N leaderboards, focusing on handling identical scores while producing an exact set of rows.

Oculus_Scores

+---------+-------+ | user_id | score | +---------+-------+ | u1 | 95 | | u2 | 92 | | u3 | 90 | | u4 | 90 | | u5 | 88 | +---------+-------+

Scenario

Meta DSPA onsite – SQL screen on Oculus dataset; need top-10 leaderboard when ranks 10 and 11 are tied.

Question

Table Oculus_Scores(user_id, score) holds daily user scores. Write a SQL query that returns exactly the top-10 users by score even when users ranked 10 and 11 have identical scores. Explain your logic.

Hints

Use DENSE_RANK vs ROW_NUMBER; trim with LIMIT or sub-query so only first 10 rows are emitted after ordering.