I have a query that I need to edit. Currently, it returns 2 columns of data, a case label and the count (or total number of cases) handled during the previous 7 day period starting yesterday. I need to change this output so that only 6 labels are in the output (i.e - always 6 rows of data). These rows need to be the top 5 labels and the sum of the remaining labels as the 6th label (called "Other"). This is because this output is fed to a PHP script that presents the data on a web-based platform.
Finally, to illustrate here is a table of the output I need as well as the query below.
+-----------+---------------+
| CaseLabel | CasesResolved |
+-----------+---------------+
| Label1 | 20 |
| Label2 | 18 |
| Label3 | 10 |
| Label4 | 9 |
| Label5 | 7 |
| Other | 12 |
+-----------+---------------+
Thanks in advance for any help! :-)
Running MySQL 5.096
MySQL Code:
SELECT
deskcases.Labels,
COUNT(deskcases.Labels)AS CaseCount
FROM
deskcases
WHERE
deskcases.Labels NOT LIKE ''
AND deskcases.Labels NOT LIKE '%SPAM%'
AND deskcases.Labels NOT LIKE '%Online Orders%'
AND deskcases.Labels NOT LIKE '%Internal SPAM%'
AND deskcases.`Case Status` LIKE 'Resolved'
AND deskcases.`Resolved At` > CURDATE()- INTERVAL 7 DAY
GROUP BY
deskcases.Labels
ORDER BY
CaseCount DESC