This query:
SELECT COUNT(source) AS count
FROM call_details
GROUP BY source
HAVING count >1
Returns about 1500 (the number I\'m looking
SELECT COUNT(count) FROM (SELECT COUNT(source) AS count
FROM call_details
GROUP BY source
HAVING count > 1) as A
You can't get a global total in a row-context. At the time the the COUNT() completes on any particular row, there's nothing to SUM, because the other rows haven't been calculated yet.
You'd have to run the SUM query first to get your individual stats, then sum manually in your script, or re-run the query with a surrounding SUM clause:
SELECT SUM(count) FROM (
SELECT original query here...
)
Just simply remove the 'Group by' clause in the select query that counts
# first, get your counts by source
SELECT COUNT(source) AS count
FROM call_details
GROUP BY source
HAVING count >1
# then, get the overall total
SELECT COUNT(source) AS count
FROM call_details
HAVING count >1
Try this
select mycount, sum(mycount) as sumcount
from
(SELECT COUNT(source) AS mycount FROM call_details GROUP BY source HAVING mycount >1) counttable
Assuming you are going to fetch all the results in the application anyway, I think the most efficient way would be to just sum it up in the application code.