我需要在日期更改时有计数行,所以我有参考日期
Date Ref
01/01/2016 1
01/01/2016 1
01/01/2016 1
02/01/2016 2
02/01/2016 2
05/01/2016 3
05/01/2016 3
05/01/2016 3
07/01/2016 4
07/01/2016 4
07/01/2016 4
07/01/2016 4
12/01/2016 5
12/01/2016 5
12/01/2016 5
12/01/2016 5
答案 0 :(得分:2)
在SQL Server中,您可以使用dense_rank()
:
select t.*, dense_rank() over (order by date) as ref
from t;