获取mysql结果的索引

时间:2011-04-24 05:58:40

标签: mysql

SELECT * FROM mydb ORDER BY score DESC LIMIT 5

它会显示5行查询,想象结果是这样的:

name      |    score
__________|___________
afrig     |    500
aminuddin |    490
andi      |    420
rosyid    |    400
hasbi     |    350

如果我有一个name参数,andi作为示例,如何将数字2(基于零)作为andi的排名?

2 个答案:

答案 0 :(得分:2)

select count(name) from mydb where score>(select score from mydb where name='andi')

答案 1 :(得分:0)

如果你的意思是你只想让查询只返回'andi'就会像这样......

SELECT * FROM mydb ORDER BY score DESC LIMIT 2,1