'SQL - Order by column where two records have the same value in a column
If I have data like this, ordered by points:
| Name | DoB | Points |
|---|---|---|
| Ben | 11/01/1990 | 2000 |
| Tom | 21/01/1980 | 1000 |
| Sam | 02/01/2001 | 500 |
| John | 01/01/2000 | 500 |
Here, I would like to rank the people in the table so their points are in order, but if two people have the same points, the person who is older will appear first, so in this case Sam should be last, and John should be second last. Any ideas how I do this?
Solution 1:[1]
Just something like that?
select *
from table
order by Points desc, cast(DoB as DATE) asc
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Liutprand |
