开发者

Filter by COUNT(*)?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜