读书人

Sql server 2005 中占位排名如何写

发布时间: 2012-08-14 10:39:58 作者: rapoo

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 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 

读书人网 >SQL Server

热点推荐