使用GROUP BY检索满足条件的记录

时间:2010-01-04 02:59:55

标签: mysql count group-by aggregate having

我只想从几千条记录中选择计数大于1的行(换句话说,重复数字),我主要看到1s,其中有几个2s和3s

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

我该怎么做?

2 个答案:

答案 0 :(得分:9)

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

答案 1 :(得分:7)

使用Having子句

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