开发者

Filter by COUNT(*)?

开发者 https://www.devze.com 2023-02-24 11:41 出处:网络
Is it possible to group results and then filter by how many rows are in the group? Something like 开发者_如何学JAVAthis:

Is it possible to group results and then filter by how many rows are in the group?

Something like 开发者_如何学JAVAthis:

SELECT * FROM mytable WHERE COUNT(*) > 1 GROUP BY name


You want to use HAVING to filter on the aggregate function.

SELECT name, COUNT(*)
    FROM mytable
    GROUP BY name
    HAVING COUNT(*) > 1


You need to use HAVING

SELECT * FROM mytable GROUP BY name HAVING COUNT(*) > 1

Although, SELECT * doesn't make much sense when you're grouping. I assume it's just for an example


You want a HAVING clause.

SELECT *
FROM mytable
GROUP BY name
HAVING COUNT(*) > 1


Use having in your query:

SELECT * FROM mytable GROUP BY name having COUNT(*) > 1 
0

精彩评论

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

关注公众号