我有这个查询,但我只想根据 num_guess 返回前 10 名。我不知道查询的格式。我不知道在哪里放 LIMIT 或 TOP。请帮忙!
"SELECT user,num_guess FROM game JOIN difficulty USING (difficulty_no) WHERE difficulty_no=2 ORDER BY num_guess ASC "
利用limit 10
像这样的东西
"SELECT user,num_guess FROM game
JOIN difficulty USING (difficulty_no)
WHERE difficulty_no=2 ORDER BY num_guess ASC limit 10"
有两个参数,第一个参数指定要返回的第一行的偏移量,第二个参数指定要返回的最大行数。初始行的偏移量为 0(不是 1):
-- SELECT * FROM tbl LIMIT 5,10; # Retrieve rows 6-15
SELECT user,num_guess FROM game
JOIN difficulty USING (difficulty_no)
WHERE difficulty_no=2 ORDER BY num_guess ASC limit 0, 10
在这种情况下,你可以在LIMIT 10
这里
是的,限制在这里有效。
SELECT user,num_guess FROM game
JOIN difficulty USING (difficulty_no)
WHERE difficulty_no=2 ORDER BY num_guess ASC LIMIT 10;
要查看更多内容,只需增加限制。
只需LIMIT 10
在查询末尾添加即可。
利用LIMIT 10
"SELECT user,num_guess FROM game
JOIN difficulty USING (difficulty_no)
WHERE difficulty_no=2 ORDER BY num_guess ASC LIMIT 10"
有关更多信息,请查看此http://dev.mysql.com/doc/refman/5.5/en//limit-optimization.html