문제

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
도움이 되었습니까?

해결책 2

Use the window function dense_rank() without a PARTITION clause:

SELECT old, dense_rank() OVER (ORDER BY old) AS new
FROM   tbl;

다른 팁

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

Fiddle Demo

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top