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
精彩评论