怎样得出表按某字段降序排序后姓名为‘张三’的记录在降序表中的位置在第几?

解决方案 »

  1.   

    select count(*) from 表名字 where 列名字> ( select 列名字 from 表名字 where name='张三')
      

  2.   

    declare @t table(id int,name varchar(14))
    insert @t select 1,'李四'
    insert @t select 2,'张三'
    insert @t select 3,'李四B'
    insert @t select 4,'李四A'
    insert @t select 5,'李四C'
    insert @t select 6,'李四D'
    insert @t select 7,'李四E'
    insert @t select 8,'李四F'
    insert @t select 9,'张三H'
    insert @t select 10,'张三K'select id,name,排名=(select count(*)+1 from @t b where b.name>a.name) from @t a order by name desc------------------------
    id         name    排名
    10 张三K 1
    9 张三H 2
    2 张三 3
    8 李四F 4
    7 李四E 5
    6 李四D 6
    5 李四C 7
    3 李四B 8
    4 李四A 9
    1 李四 10