总计重复次数

时间:2012-12-04 17:20:44

标签: mysql sum

我有这个在我的数据库中找到所有重复项:

SELECT phone, count(*) AS ct FROM table GROUP BY `phone` HAVING ct >1

这导致12行,但这12行的ct之和等于26:

phone      ct
3600000000  4
3602931205  2
3602933399  2
3602933736  2
3602936241  2
3602937911  2
3602939287  2
3602939353  2
3602939767  2
3603174530  2
3606612300  2
3608995913  2

如何修改查询以告诉我ct的总数?

1 个答案:

答案 0 :(得分:2)

试试这个::

Select SUM(temp_1.count_1) as totalCount
from
(
SELECT phone, count(1) AS count_1 FROM table GROUP BY `phone` HAVING count_1 >1) as temp_1