SELECT
/*Analyser*/
DECODE(state,
1,'Wait',
2,'Ready',
3,'Running',
5,'Blocked',
6,'Hold',
7,'Cancelling',
9,'Cancelled',
10,'Error',
12,'Succeeded',
13,'Paused',
19,'Error_Manual_Recovery',
state) AS Status,
COUNT(requestid) AS count
FROM
FUSION.ESS_REQUEST_HISTORY
WHERE
state IN (2,3,5,6,7,13,19)
GROUP BY state
ORDER BY COUNT(requestid) DESC;