1

我有这个查询,但我只想根据 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 "
4

5 回答 5

3

利用limit 10

像这样的东西

"SELECT user,num_guess FROM game 
 JOIN difficulty USING (difficulty_no) 
 WHERE difficulty_no=2 ORDER BY num_guess ASC limit 10"
于 2013-03-31T07:57:43.003 回答
1

有两个参数,第一个参数指定要返回的第一行的偏移量,第二个参数指定要返回的最大行数。初始行的偏移量为 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这里

于 2013-03-31T08:00:18.203 回答
0

是的,限制在这里有效。

SELECT user,num_guess FROM game 
    JOIN difficulty USING (difficulty_no) 
        WHERE difficulty_no=2 ORDER BY num_guess ASC LIMIT 10;

要查看更多内容,只需增加限制。

于 2013-03-31T13:07:05.973 回答
0

只需LIMIT 10在查询末尾添加即可。

于 2013-03-31T07:58:46.923 回答
0

利用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

于 2013-03-31T08:04:27.673 回答