How do I generate row number without using rownum() in sql server

前端 未结 4 570
伪装坚强ぢ
伪装坚强ぢ 2021-01-14 22:37

I have the following table:

CREATE table prd
(
prdid varchar(10)
)
insert into prd values (\'prd1011\'),(\'prd1023\'),(\'prd4532\'),(\'prd2341\')
         


        
4条回答
  •  再見小時候
    2021-01-14 23:11

    I tried this and it worked but it is working only if the prdid column is unique:

    select prdid,
    (select COUNT(*) from prd p where p.prdid >= r.prdid)rnk
    from prd r order by rnk
    

提交回复
热议问题