日期:2014-05-18  浏览次数:20507 次

Sql server 2005 中占位排名怎么写?
有一个表里有多条记录,有一个积分字段,我现在想做一个视图,得到这些记录按积分的排名
例如有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 all
select 1000 union all
select 400 union all
select 400 union all
select 100

select *,RANK() OVER(ORDER BY id desc) AS [rank] from @t
--------------------------
id          rank
----------- --------------------
1000        1
1000        1
400         3
400         3
100         5