본문으로 바로가기

[MS-SQL] row_number() over 사용하기

category Dev/MS-SQL 2016. 9. 7. 15:53
-- 특정 그룹별로 일련번호
select groupCode, row_number() over(PARTITION BY hCode order by groupCode desc) as rowNo
from ollagaza

* RESULT
A  1
A  2
A  3
A  4
B  1
B  2
C  1
C  2
C  3
-- 전체 일련번호
select groupCode, row_number() over(order by groupCode desc) as rowNo
from ollagaza
where hCode LIKE 'JPTYO%'

* RESULT
A  1
A  2
A  3
A  4
B  5
B  6
C  7
C  8
C  9

댓글을 달아 주세요