Description
Write a SQL query to rank scores from highest to lowest. Same scores should have the same rank (dense ranking). Return score and rank, ordered by score descending. **Output columns (in order):** score, rank
Table:
scores| Column | Type |
|---|---|
| id | INT |
| score | REAL |
Examples
Input:
CREATE TABLE scores (id INT, score REAL); INSERT INTO scores VALUES (1, 3.65), (2, 3.85), (3, 4.0);Output:
4.0|1
3.85|2
3.65|3Explanation:
Scores are ranked from highest to lowest: 4.0 is rank 1, 3.85 is rank 2, 3.65 is rank 3.
Input:
CREATE TABLE scores (id INT, score REAL); INSERT INTO scores VALUES (1, 2.75), (2, 2.75), (3, 2.75), (4, 1.5);Output:
2.75|1
2.75|1
2.75|1
1.5|2Explanation:
Multiple scores tied for first place all receive rank 1, and the next different score gets rank 2 (not rank 4), demonstrating how tied scores affect ranking
Input:
CREATE TABLE scores (id INT, score REAL); INSERT INTO scores VALUES (1, 5.0), (2, 4.5), (3, 4.0), (4, 3.5), (5, 3.0);Output:
5.0|1
4.5|2
4.0|3
3.5|4
3.0|5Explanation:
All scores are unique and distinct, so each score gets consecutive ranks from 1 to 5 in descending order
Constraints
- •
Same scores get same rank