WITH YF AS ( SELECT a.ZL,a.LSJ ,A.KFKS ksbh,sfbm FROM A
WHERE A.ZXRQ >=TO_DATE('2019-01-01','YYYY-MM-DD') AND A.ZXRQ <TO_DATE('2020-01-01','YYYY-MM-DD') UNION ALL SELECT a.ZL ,a.LSJ ,A.KFKS ksbh,sfbm FROM A
WHERE A.ZXRQ >=TO_DATE('2019-01-01','YYYY-MM-DD') AND A.ZXRQ <TO_DATE('2020-01-01','YYYY-MM-DD')
)
select ksbh,
sum(decode(sfbm,'c',zl*lsj,0)) as cyf,
sum(decode(sfbm,'a',zl*lsj,0)) as xyf,
sum(decode(sfbm,'b',zl*lsj,0)) as zyf
from YF
group by ksbh;
with 创建临时表 这个语法寿面必须跟select