My question is continuation of this probem Link
I have a dataset such as this one:
ID | Date
A 01/01/2015
A 02/01/2015
A 02/01/2015
A 02/01/2015
A 05/01/2015
B 01/01/2015
I want to rank each date by a referential date - 31/01/2015. The closest date to the referential date being ranked 1, second 2, and so on. The result would look like:
ID | Date | Sequence
A 01/01/2015 3
A 02/01/2015 2
A 02/01/2015 2
A 02/01/2015 2
A 05/01/2015 1
B 01/01/2015 ...
While the rank function does think, I also want to keep all the ties. How do I do that?
Also, I am working with a huge dataset - approx. 300 million rows. So the solution would ideally be fast.