
Points above the contest average
mediumPoints above the contest average
DraftKings SQL Interview Question
A DraftKings score means nothing on its own, because a low scoring slate drags every lineup down. What tells a player whether they drafted well is the distance from the average of the contest they were actually in, and that is what the results screen shows them.
Return the contest_id, the user_id, their points, and how far above or below their contest's average they finished as points_vs_average, rounded to 2 decimal places.
Asked of
- Data Analyst
- Business Analyst
- BI Analyst
- Product Analyst
- Analytics Engineer
- Data Engineer
- Data Scientist
draftkings_contest_entriesTable28 rows
| Column Name | Type |
|---|---|
| entry_id | BIGINT |
| contest_id | VARCHAR |
| user_id | VARCHAR |
| joined_at | TIMESTAMP |
| points | DOUBLE |
draftkings_contest_entriesExample Input
| entry_id | contest_id | user_id | joined_at | points |
|---|---|---|---|---|
| 3101 | C1 | U100 | 2024-03-20 18:05:00 | 742.5 |
| 3102 | C1 | U101 | 2024-03-20 18:11:00 | 801 |
| 3103 | C1 | U102 | 2024-03-20 18:14:00 | 801 |
| 3104 | C1 | U103 | 2024-03-20 18:22:00 | 689.5 |
| 3105 | C1 | U104 | 2024-03-20 18:30:00 | 742.5 |
| 3106 | C1 | U105 | 2024-03-20 18:41:00 | 655 |
| 3107 | C1 | U106 | 2024-03-20 18:52:00 | 812.5 |
| 3120 | C4 | U100 | 2024-03-23 17:30:00 | 455.5 |
| 3121 | C4 | U107 | 2024-03-23 17:38:00 | 455.5 |
| 3122 | C4 | U108 | 2024-03-23 17:49:00 | 603 |
| 3123 | C4 | U110 | 2024-03-23 17:55:00 | 588.5 |
| 3124 | C4 | U111 | 2024-03-23 18:04:00 | 721.5 |
Example Output
| contest_id | user_id | points | points_vs_average |
|---|---|---|---|
| C1 | U100 | 742.5 | -6.64 |
| C1 | U101 | 801 | 51.86 |
| C1 | U102 | 801 | 51.86 |
| C1 | U103 | 689.5 | -59.64 |
| C1 | U104 | 742.5 | -6.64 |
| C1 | U105 | 655 | -94.14 |
| C1 | U106 | 812.5 | 63.36 |
| C4 | U100 | 455.5 | -109.3 |
| C4 | U107 | 455.5 | -109.3 |
| C4 | U108 | 603 | 38.2 |
| C4 | U110 | 588.5 | 23.7 |
| C4 | U111 | 721.5 | 156.7 |
Explanation
C1 averaged 749.14 points, so U106 on 812.5 finished 63.36 above it and U105 on 655 finished 94.14 below. C4 is a lower scoring contest, so 603 there is 38.2 above its own average rather than below.
The example above is a small slice of the data. Your query runs against the full tables.
Company
DraftKings
Difficulty
medium
Topic
window functions
Language
SQL
Your query
Starting the SQL engine...