Rank scores
MediumP2Coding
Table scores:
| Column | Type |
|---|---|
| id | int (primary key) |
| score | numeric(4,2) |
Rank the scores from highest to lowest. Equal scores get the same rank, and the next rank is the next integer (no gaps): 4.00, 4.00, 3.85 gets ranks 1, 1, 2.
Output columns: score, score_rank. Return one row per input row, highest score first.
Schema
CREATE TABLE scores ( id int PRIMARY KEY, score numeric(4,2) NOT NULL );
Example 1
- Input
- scores: (1, 3.50), (2, 3.65), (3, 4.00), (4, 3.65)
- Output
- (4.00, 1), (3.65, 2), (3.65, 2), (3.50, 3)
Constraints
- PostgreSQL dialect.
Hints
Give it a real attempt first. Run shows which examples fail.
Saved automatically
PostgreSQL
Run checks the 3 visible tests, Submit all 5. ⌘Enter runs, ⌘⇧Enter submits.