MySQL query - using SUM of COUNT

后端 未结 5 932
刺人心
刺人心 2021-01-07 16:27

This query:

SELECT COUNT(source) AS count
FROM call_details
GROUP BY source
HAVING count >1

Returns about 1500 (the number I\'m looking

5条回答
  •  悲&欢浪女
    2021-01-07 16:47

    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...
    )
    

提交回复
热议问题