Prize ranks with ties

ranking

Prize ranks with ties

DraftKings SQL Interview Question

DraftKings pays prize money by finishing position, and two lineups on identical points have to finish level. Standard contest scoring applies: tied lineups share the better position, and the next position down is skipped by as many lineups as tied.

Return the contest_id, the user_id, their points, and their finishing position as prize_rank. Sort by contest_id and then by prize_rank.

Asked of

  • Data Analyst
  • Business Analyst
  • BI Analyst
  • Product Analyst
  • Analytics Engineer
  • Data Engineer
  • Data Scientist

draftkings_contest_entriesTable28 rows

Column NameType
entry_idBIGINT
contest_idVARCHAR
user_idVARCHAR
joined_atTIMESTAMP
pointsDOUBLE

draftkings_contest_entriesExample Input

entry_idcontest_iduser_idjoined_atpoints
3101C1U1002024-03-20 18:05:00742.5
3102C1U1012024-03-20 18:11:00801
3103C1U1022024-03-20 18:14:00801
3104C1U1032024-03-20 18:22:00689.5
3105C1U1042024-03-20 18:30:00742.5
3106C1U1052024-03-20 18:41:00655
3107C1U1062024-03-20 18:52:00812.5
3120C4U1002024-03-23 17:30:00455.5
3121C4U1072024-03-23 17:38:00455.5
3122C4U1082024-03-23 17:49:00603
3123C4U1102024-03-23 17:55:00588.5
3124C4U1112024-03-23 18:04:00721.5

Example Output

contest_iduser_idpointsprize_rank
C1U106812.51
C1U1018012
C1U1028012
C1U100742.54
C1U104742.54
C1U103689.56
C1U1056557
C4U111721.51
C4U1086032
C4U110588.53
C4U100455.54
C4U107455.54

Explanation

In C1 two lineups tie on 801 points and both finish second. The next one down finishes fourth rather than third, because two places have already been used. It happens again at 742.5, where two lineups share fourth and the next is sixth.

The example above is a small slice of the data. Your query runs against the full tables.