有一个表里有多条记录,有一个积分字段,我现在想做一个视图,得到这些记录按积分的排名
例如有5条记录 积分是1000,1000,400,400,100
我想得到的排序顺序是
1,1,3,3,5这样的占位排名
这样的sql应该怎么写?
------解决方案--------------------
rank_over()
------解决方案--------------------
- SQL code
select *,RANK() OVER(ORDER BY 积分) AS [rank] from tb
------解决方案--------------------
RANK() OVER(ORDER BY )
------解决方案--------------------
- SQL code
declare @t table(id int)insert into @t select 1000 union allselect 1000 union allselect 400 union allselect 400 union allselect 100select *,RANK() OVER(ORDER BY id desc) AS [rank] from @t--------------------------id rank----------- --------------------1000 11000 1400 3400 3100 5