[英]Retrieve the top 10 from the database
我有這個查詢,但我只想根據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
只需在查詢結尾添加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
是的限制可以在這里工作。
SELECT user,num_guess FROM game
JOIN difficulty USING (difficulty_no)
WHERE difficulty_no=2 ORDER BY num_guess ASC LIMIT 10;
要查看更多只是增加限制。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.