Further Ordering
Question:
For cats age means seniority, we would like to rank the cats by age (oldest first).
However we would like their ranking to be sequentially increasing.
Return: ranking, name, age
Order by: ranking, name Show Table Schema
Cats:
name | varchar |
breed | varchar |
weight | float |
color | varchar |
age | int |
Correct output but can you use 'dense_rank'?
×
Good work!
dense_rank() differs from rank() as it increases sequentially.
Consider a race where 2 people finished first. Dense_rank assigns the next person 2nd. Rank assigns them 3rd.
next question
Desired output:
r | name | age |
1 | Alfie | 5 |
1 | Ashes | 5 |
1 | Millie | 5 |
2 | Charlie | 4 |
2 | Smokey | 4 |
2 | Smudge | 4 |
3 | Felix | 2 |
3 | Misty | 2 |
3 | Puss | 2 |
3 | Tigger | 2 |
4 | Molly | 1 |
4 | Oscar | 1 |
select dense_rank() over (order by age DESC) as r, name,age from cats order by r, name