select decode(no, 1, dname, 2, dname||' 소계', '합계') dname,
decode(no, 1, job ) job ,
sum(cnt) cnt
from ( select dname, job, cnt
from
( select deptno, job, count(*) cnt
from emp
group by deptno, job) emp,dept
where emp.deptno = dept.deptno),
( select 1 no from dual
union all
select 2 no from dual
union all
select 3 no from dual)
group by no,
decode(no, 1, dname, 2, dname||' 소계', '합계'),
decode(no, 1, job )