I am trying to create a MySQL query (MySQL v5) that totals call records by day/inbound number with a running cumulative total. I have referenced other pages on Stack Overflow but the results I'm getting are not adding up.
References: MYSQL cumulative sum by date MySQL cumulative sum order by date
The query looks like so:
SET @RUNNING_TOTAL :=0;
SELECT
DATE_FORMAT(start,'%d/%m/%Y') As CallDate,
ch.did AS InboundNo,
COUNT(*) AS DayTotal,
(@RUNNING_TOTAL := @RUNNING_TOTAL + COUNT(*)) AS CumulativeCalls
FROM
`call_history` ch
LEFT JOIN (SELECT callid, event FROM ast_queue_log WHERE event = 'ENTERQUEUE') aql ON aql.callid = ch.callid
WHERE
ch.did = '01234567891' AND
start BETWEEN DATE_FORMAT(NOW() ,'%Y-%m-01') AND NOW()
GROUP BY
ch.did, DATE(start)
ORDER BY
ch.did;
I would expect the following output:
+-------------------------------+-------------+----------+-----------------+
| CallDate | InboundNo | DayTotal | CumulativeCalls |
+-------------------------------+-------------+----------+-----------------+
| 01/05/2020 | 01234567891 | 232 | 232 |
| 02/05/2020 | 01234567891 | 50 | 282 |
| 03/05/2020 | 01234567891 | 14 | 296 |
| 04/05/2020 | 01234567891 | 246 | 542 |
| 05/05/2020 | 01234567891 | 187 | 729 |
| 06/05/2020 | 01234567891 | 182 | 911 |
| 07/05/2020 | 01234567891 | 105 | 1016 |
| 08/05/2020 | 01234567891 | 46 | 1062 |
| 09/05/2020 | 01234567891 | 26 | 1088 |
| 10/05/2020 | 01234567891 | 7 | 1095 |
| 11/05/2020 | 01234567891 | 255 | 1350 |
+-------------------------------+-------------+----------+-----------------+
What I am getting is the same values in DayTotal and CumulativeCalls for each day.