select a.regiono,a.deptno,a.emp_name,sum(a.prem)
from pos_accept a
where a.date >= to_date('20030901','yyyymmdd')
and a.date < to_date('20030930','yyyymmdd')
group by a.regiono,a.deptno,a.emp_name
order by a.deptno
union
select '','','',sum(a.prem) from pos_accept a
where a.date >= to_date('20030901','yyyymmdd')
and a.date < to_date('20030930','yyyymmdd')
from pos_accept a
where a.date >= to_date('20030901','yyyymmdd')
and a.date < to_date('20030930','yyyymmdd')
group by a.regiono,a.deptno,a.emp_name
order by a.deptno
union
select '','','',sum(a.prem) from pos_accept a
where a.date >= to_date('20030901','yyyymmdd')
and a.date < to_date('20030930','yyyymmdd')
from pos_accept a
where a.date >= to_date('20030901','yyyymmdd')
and a.date < to_date('20030930','yyyymmdd')
group by a.regiono,a.deptno,a.emp_name
order by a.deptno
union
select '','','',sum(a.prem) from pos_accept a
where a.date >= to_date('20030901','yyyymmdd')
and a.date < to_date('20030930','yyyymmdd');执行以后出现提示这样一个错误:
union
*
第7行有错:
ORA-00933: SQL command not properly ended
单独执行上一段和下一段都是没有问题的。
用union all
from pos_accept a
where a.date >= to_date('20030901','yyyymmdd')
and a.date < to_date('20030930','yyyymmdd')
group by a.regiono,a.deptno,a.emp_name
union all
select '总计','','',sum(a.prem) from pos_accept a
where a.date >= to_date('20030901','yyyymmdd')
and a.date < to_date('20030930','yyyymmdd')
order by 1;