Use the window function dense_rank()
without a PARTITION
clause:
SELECT old, dense_rank() OVER (ORDER BY old) AS new
FROM tbl;
Domanda
How to change the old sequence in the column to new in using sql server 2005
old new
1 1
1 1
3 2
4 3
5 4
5 4
5 4
8 5
8 5
10 6
Soluzione 2
Use the window function dense_rank()
without a PARTITION
clause:
SELECT old, dense_rank() OVER (ORDER BY old) AS new
FROM tbl;
Altri suggerimenti
I think you're looking for dense_rank
:
select dense_rank() over (order by old) rn, old
from yourtable
order by old
Are you looking for DENSE_RANK()
SELECT
T.*
,DENSE_RANK() OVER (ORDER BY T.Old) As New
FROM Table1 T