MySQL查询-使用COUNT之和 [英] MySQL query - using SUM of COUNT
本文介绍了MySQL查询-使用COUNT之和的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
此查询:
SELECT COUNT(source) AS count
FROM call_details
GROUP BY source
HAVING count >1
仅使用count字段返回大约1500个(我正在寻找的数字)结果.我如何还可以返回所有计数字段的总和?当我尝试
Returns about 1500 (the number I'm looking for) results with only the count field. How could I also return the sum of all count fields? When I try
SELECT COUNT(source) AS count,
SUM(count) as total
FROM call_details
GROUP BY source
HAVING count >1
我在字段列表"中收到未知列"计数".
I get an 'Unknown column 'count' in 'field list' error.
还有
SELECT COUNT(source) AS count,
SUM(COUNT(source)) as total
FROM call_details
GROUP BY source
HAVING count >1
给我一个无效使用组功能"
gives me an 'Invalid use of group function'
有什么想法吗?我可以做第一组的mysql_num_rows($result)
(以获取所需的信息),但我真的很想通过MySQL来做.
Any ideas? I can do a mysql_num_rows($result)
of the first set (to get the info I need) but I really want to do it through MySQL.
推荐答案
SELECT COUNT(count) FROM (SELECT COUNT(source) AS count
FROM call_details
GROUP BY source
HAVING count > 1) as A
这篇关于MySQL查询-使用COUNT之和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文