task RANK / DENSE_RANK · medium
Predict: positions and shared ranks
Predict the three ranking columns for the sample of Seattle hitters.
what to return
- Columns
player_idhome_runsrnkdenserow_numin this order- Rows
- in the order asked
- Watch for
- Use only the sample rows shown. NULL is not zero or empty text. Keep duplicate rows.
- Skill
- Reason about the exact result of a fixed SQL query. Refresher: RANK & DENSE_RANK →
data you can query
Sports dataset: the first 6 rows of each table. Under each column name: the kind of value it holds, and which table it links to. Your queries run on all rows.
hitter_sample2 columns · 7 rows
| player_id | home_runs |
|---|---|
| canzd001 | 11 |
| crawj002 | 12 |
| garvm001 | 9 |
| moord002 | 9 |
| naylj001 | 9 |
| suare001 | 13 |
- player_id
- canzd001
- home_runs
- 11
- player_id
- crawj002
- home_runs
- 12
- player_id
- garvm001
- home_runs
- 9
- player_id
- moord002
- home_runs
- 9
- player_id
- naylj001
- home_runs
- 9
- player_id
- suare001
- home_runs
- 13
first 6 of 7 rows · your queries use all of them
SELECT player_id, home_runs, RANK() OVER (ORDER BY home_runs DESC) AS rnk, DENSE_RANK() OVER (ORDER BY home_runs DESC) AS dense, ROW_NUMBER() OVER (ORDER BY home_runs DESC, player_id) AS row_num FROM hitter_sample ORDER BY row_num
SELECT player_id, home_runs, RANK() OVER (ORDER BY home_runs DESC) AS rnk, DENSE_RANK() OVER (ORDER BY home_runs DESC) AS dense, ROW_NUMBER() OVER (ORDER BY home_runs DESC, player_id) AS row_num FROM hitter_sample ORDER BY row_num
Look at the sample tables and SQL. Enter the rows you think the query returns, in this column order: player_id, home_runs, rnk, dense, row_num. Put each row in square brackets, then wrap all rows in another pair of brackets (JSON format). For example, [[1,null,null,null,null]] is one row with 5 values. Replace these with your predicted values. Use numbers without quotes, text in double quotes, and null for SQL NULL. Keep repeated rows. Use [] for no rows. Keep rows in the order specified by ORDER BY.
Hints and the answer are always available. Using them counts the question as solved with help.