问一个问题:
表名 MySongs
***********************
UID  Vote
1     9
2     8
3     24
4     10
........................Votes按降序排.我要得到UID=4在整个表记录中的名次,怎样写这个sql语句?应该得到的结果是: 2
麻烦大人们帮写一下这条sql语句.

解决方案 »

  1.   

    select count(*) from demo where vote<(select vote from demo where uid=4)
      

  2.   

    更正一下,刚才忘了加自己了:
    select count(*)+1 from demo where vote<(select vote from demo where uid=4)
      

  3.   

    like this:select count(1) from mysongs where vote >=(select vote from mysongs  where uid=4)
      

  4.   

    但是这样有一个问题.如果Votes值有相同,结果就如下.
    UID   Votes  正确结果  上面的sql得到的结果
    1      20    1           1
    2       5    3           4
    3      18    2           2
    4       5    3           4
    5       5    3           4
    这样结果就不对了.............
    那位能给出正确的啊?