有数据表
username   votenum
  a           15
  b           20
  c           30
写一个sql语句查询出用户所对应的票数排行如:输入c 查询的结果为:1

解决方案 »

  1.   

    select rn from
    (select username,row_number() over(order by votenum) rn from tbl) t 
    where username='c'
      

  2.   

    select rn from
    (select username,row_number() over(order by votenum desc) rn from tbl) t 
    where username='c'
      

  3.   


    Select username, votenum, (Select count(*) + 1 from tbl where votenum > t.votenum) from tbl t
    order by votenum desc