In MySQL, probabilmente il modo più semplice per esprimerlo è usare una tabella temporanea:
create temporary table temp as (
id int not null auto_increment,
CaseLabel varchar(255),
CasesResolved int
);
insert into temp(CaseLabel, CasesResolved)
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;
select (case when id <= 5 then caselabel else 'Other' end),
SUM(casesResolved) as CasesResolved
from temp
group by (case when id <= 5 then caselabel else 'Other' end)
order by MAX(id) desc
L'id
colonna nella tabella temporanea aggiunge un numero di riga a ciascuna riga. In qualsiasi altro database reale, useresti il row_number()
funzione, ma MySQL non lo supporta.