oracle分门别类的统计列数据

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/cxws110/article/details/86528202

select t.dept ,t.deptcode,t.prpjdepartname ,t.projcode,
    sum(case when t.cost_type='办公日常' then t.budget_moneyhj end) bgys,
    sum(case when t.cost_type='办公日常' then t.cost_actual end) bgfy,
    sum(case when t.cost_type='办公日常' then t.comp_rate end) bgwcl,
    sum(case when t.cost_type='项目费用' then t.budget_moneyhj end) xmys,
    sum(case when t.cost_type='项目费用' then t.cost_actual end) xmfy,
    sum(case when t.cost_type='项目费用' then t.comp_rate end) xmwcl,
    sum(case when t.cost_type='市场费用' then t.budget_moneyhj end) scys,
    sum(case when t.cost_type='市场费用' then t.cost_actual end) scfy,
    sum(case when t.cost_type='市场费用' then t.comp_rate end) scwcl,
    sum(case when t.cost_type='其他费用' then t.budget_moneyhj end) qtys,
    sum(case when t.cost_type='其他费用' then t.cost_actual end) qtfy,
    sum(case when t.cost_type='其他费用' then t.comp_rate end) qtwcl,
    sum(t.budget_moneyhj) yshj,
    sum(t.cost_actual) fyhj,
    round((case when sum(t.budget_moneyhj) is null then 0 when sum(t.budget_moneyhj)=0 then 0 else sum(t.cost_actual)/sum(t.budget_moneyhj)*100 end),2) wcl
    from w_fm_budget t
    where 1=1 --<if test="@Ognl@isNotEmpty(dept)"> AND DEPT  LIKE #{dept}  </if>
   -- <!-- AND BUDGET_YEAR=to_char(sysdate,'yyyy') -->
    AND BUDGET_YEAR=(select case
         when to_char(sysdate, 'mm-dd') >= '12-23' then
          (to_char(sysdate, 'yyyy')+1)
         else
          (to_char(sysdate, 'yyyy')+0)
       end 
      FROM DUAL)
    group by t.dept,t.deptcode,t.prpjdepartname,t.projcode
    order by abs(t.deptcode),abs(t.projcode)

展示结果如下:

猜你喜欢

转载自blog.csdn.net/cxws110/article/details/86528202