开发者

Can i limit my result to a specific number in sql?

开发者 https://www.devze.com 2023-03-24 23:43 出处:网络
Select count(*) as c from casting where ord = 1 Group by actorid Order by count(*) DESC The result is
Select count(*) as c from casting where ord = 1 Group by actorid Order by count(*) DESC 

The result is

15 15 14 13 12 10 7 7 开发者_StackOverflow7 7 5 5

Then i would like to get the result only greater than 10 ??how to do that thanks~~


SELECT count(*) AS c 
FROM casting 
WHERE ord = 1 
GROUP BY actorid 
HAVING c > 10
ORDER BY c DESC

You can consider HAVING the WHERE clause for GROUP BY aggregates.


SELECT COUNT(*) AS c FROM casting WHERE ord = 1 GROUP BY actorid HAVING COUNT(*) > 10 ORDER BY COUNT(*) DESC


HAVING c > 10

Place this between group by and order by

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号