I have the following query which displays sum of employees in a particular group (A1,B1..etc) and in a specifc department.
The problem is when there is no data for a specific department at a specific date then that row with the department name is not displayed at all and I want the query to display all the rows/department names even if they have data in it or not. It should display '0' in such a case.
SELECT NVL(TO_CHAR(COALESCE(dept_name,'NA') ),'TOTAL') AS Department,
SUM (
CASE
WHEN ( emp_group IN('ABC','CDE','EFG','GHI'))
THEN 1
ELSE 0
END) AS A1,
SUM(
CASE
WHEN ( emp_group IN ('XYZ'))
THEN 1
ELSE 0
END) AS B1,
SUM (
CASE
WHEN ( emp_group IN ('ABC','CDE','EFG','GHI','XYZ'))
THEN 1
ELSE 0
END) AS TOTAL
FROM emp e
WHERE
dept_name IN('IT','FI','ACC')
AND e.transaction_date = trunc(sysdate)
GROUP BY rollup(COALESCE(dept_name,'NA'))
Thanks in advance