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')

解决方案 »

  1.   

    如果说只是最后再加一个合计,我同意 hdkkk(diablo2) 的做法,Union应该是可以的。
      

  2.   

    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');执行以后出现提示这样一个错误:
    union
    *
    第7行有错:  
    ORA-00933: SQL command not properly ended
      单独执行上一段和下一段都是没有问题的。
      

  3.   

    另外,union 自动排序
    用union all
      

  4.   

    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
    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;