id   hit   
1    10
2    20
3    30
4    50
5    8 
6    70
7    9按hit排,我想知道id=3的排在第几位?谢谢

解决方案 »

  1.   

    select id,hit,(select count(*) from d where hit>=t.hit) as b from d t where id=3 order by b
      

  2.   

    create table k (id int ,hit int)
    insert  k select 1,10
    union all select 2,20
    union all select 3,30
    union all select 4,50
    union all select 5,8
    union all select 6,70
    union all select 7,9若按hit的降序
    select h=count(*) from k a where not exists (select hit from k where id=3  and hit<a.hit)
    若按hit的升序
    总数减h