日期:2014-05-19  浏览次数:20496 次

怎样知道一条数据在不同排序方法下的排名?
如题

------解决方案--------------------
增加一个自增列查看排名
------解决方案--------------------
select num = (select count(1) form table a where a.排序字段 < 排序字段 order by a.排序字段 ) from table
------解决方案--------------------
create table test(id int,age int)
insert test select 1,20
union all select 2,36
union all select 4,10
union all select 10,25
union all select 11,23
union all select 6,38

select bh=identity(int,1,1),* into # from test

select bh from # where id=10
order by age

drop table test,#

bh
-----------
4
------解决方案--------------------
select id,[排名]=(select count(1) from [user] where [user].[年龄] <=a.[年龄]) from [user] a where id=10