I need your help, I have a query in my system, which has 4 cases
SELECT TOP 3 * FROM (
SELECT Title, SUM(Count) AS Count
FROM (
SELECT
CASE WHEN EstadoId = EstadoIdAutor AND EstadoId = Meddoc1 AND EstadoId = Meddoc2 AND EstadoId = Meddoc3 THEN
'Sem deslocamento'
ELSE
CASE WHEN EstadoId = EstadoIdAutor AND (EstadoId = Meddoc1 OR EstadoId = Meddoc2 OR EstadoId = Meddoc3) THEN
'Fora de domicílio do autor'
ELSE
CASE WHEN EstadoId <> EstadoIdAutor OR (EstadoId = EstadoIdAutor AND (EstadoId <> Meddoc1 AND EstadoId <> Meddoc2 AND EstadoId <> Meddoc3)) THEN
'Mais de um deslocamento'
ELSE 'Outros'
END
END
END AS Title,
COUNT(*) AS Count
FROM jud_Processos
WHERE Status = 1 AND Trancado = 1 {dados}
GROUP BY EstadoId, EstadoIdAutor, Meddoc1, Meddoc2, Meddoc3
) Sub
GROUP BY Title
) TB_AUX
I would like to know if it is possible to split this query which in this case would be in 4 parts
No displacement - Outside the author's home - More than one displacement - Other
Is it possible?
To be more specific, each case
in a select
.