How do I create a column that ranks each ID by the First and Last Date?
ID First_Date Last_Date Age_Days
A 8/28/2020 12/22/2020 116
A 1/9/2019 8/12/2019 215
A 8/15/2019 8/28/2020 379
B 5/23/2017 1/9/2019 596
B 9/21/2019 3/16/2020 177
C 3/18/2020 9/29/2020 195
Desired Result:
ID Initial_Date Last_Date Age_Days New_Column
A 1/9/2019 8/12/2019 215 1
A 8/15/2019 8/28/2020 379 2
A 8/28/2020 12/22/2020 116 3
B 5/23/2017 1/9/2019 596 1
B 9/21/2019 3/16/2020 177 2
C 3/18/2020 9/29/2020 195 1
My example SQL Server query:
SELECT
ID, First_Date, Last_Date, Age_Days
FROM Table
ORDER BY ID, First_Date, Last_Date
DENSE_RANK