You could use conditional aggregation
:
SELECT ANALYST
,COUNT(CASE WHEN status = 'unchecked' THEN 1 END) AS unchecked
,COUNT(CASE WHEN status = 'observation' THEN 1 END) AS observation
,COUNT(CASE WHEN status = 'supervisor' THEN 1 END) AS supervisor
,COUNT(CASE WHEN status = 'pending' THEN 1 END) AS pending
,COUNT(CASE WHEN status = 'closed' THEN 1 END) AS closed
,COUNT(*) AS Grand_Tot
FROM tab
GROUP BY ANALYST
ORDER BY ANALYST;
EDIT:
Can i know how to SUM the Grand_Tot Column along with that query i was trying SUM(Grand_Tot) but getting error as invalid identifier.
One way is to use subquery:
SELECT sub.*, SUM(Grand_Tot) OVER() AS Sum_Grant_Tot
FROM (
SELECT ANALYST
,COUNT(CASE WHEN status = 'unchecked' THEN 1 END) AS unchecked
,COUNT(CASE WHEN status = 'observation' THEN 1 END) AS observation
,COUNT(CASE WHEN status = 'supervisor' THEN 1 END) AS supervisor
,COUNT(CASE WHEN status = 'pending' THEN 1 END) AS pending
,COUNT(CASE WHEN status = 'closed' THEN 1 END) AS closed
,COUNT(*) AS Grand_Tot
FROM tab
GROUP BY ANALYST
) sub
ORDER BY ANALYST;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.