Retrieving records fulfilling a condition using GROUP BY

那年仲夏 提交于 2019-11-29 18:49:02

问题


I'd like to only select the rows where the count is greater than 1 (in other words the duplicates) right now from a few thousand records I am mostly seeing 1s with a few 2s and 3s here and there

SELECT count( * ) AS `Number` , GI . *
FROM `GeneralInformation` AS GI
GROUP BY `FirstName` , `Surname` 

how can I do this?


回答1:


SELECT count( * ) AS `Number` , GI . *
FROM `GeneralInformation` AS GI
GROUP BY `FirstName` , `Surname` 
HAVING count(*)>1



回答2:


Use the Having clause

SELECT count( * ) AS `Number` , GI . *
FROM `GeneralInformation` AS GI
GROUP BY `FirstName` , `Surname` 
HAVING count( * ) > 1


来源:https://stackoverflow.com/questions/1997307/retrieving-records-fulfilling-a-condition-using-group-by

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!