日期:2014-05-17 浏览次数:20598 次
SELECT * FROM (select n.kjnd,n.gsdm,m.ysdwdm,m.gsmc,n.M1,n.L1,n.M2,n.L2,n.M3,n.L3 from
(select gsdm as ysdwdm,gsmc from pubgszl where gsdm like '11700%' ) as m
left join
(Select
a.KJND,
a.GSDM,
a.YSDWDM,
a.M1,
L1=SUM(CASE WHEN (b.ZBLYDM like '0601%'or b.ZBLYDM like '0501%' or b.ZBLYDM like '0401%') THEN b.JE ELSE 0 END),
a.M2,
L2=SUM(CASE WHEN (b.ZBLYDM like '0601%') THEN b.JE ELSE 0 end),
a.M3,
L3=SUM(CASE WHEN (b.ZBLYDM like '0401%'or b.ZBLYDM like '0501%') THEN b.JE ELSE 0 end)
from
(Select
KJND,
GSDM,
YSDWDM,
M1=SUM(CASE WHEN (ZBLYDM like '0601%'or ZBLYDM like '0501%' or ZBLYDM like '0401%') THEN JE ELSE 0 END),
M2=SUM(CASE WHEN (ZBLYDM like '0601%') THEN JE ELSE 0 end),
M3=SUM(CASE WHEN (ZBLYDM like '0401%'or ZBLYDM like '0501%') THEN JE ELSE 0 end)
from ZB_MXZB
WHERE
(ZBZT<>'2') and (substring(sh_rq,1,6)= '201211') and (shr_id<>-1) and (ysdwdm like '117%') ---参数设置
GROUP BY KJND,GSDM,YSDWDM) a,zb_mxzb as b--,pubgszl as c
WHERE a.KJND=b.KJND AND a.GSDM=b.GSDM AND a.YSDWDM=b.YSDWDM and (substring(b.sh_rq,1,6)<= '201211') and shr_id<>-1--and a.ysdwdm=c.gsdm---参数设置
GROUP BY a.KJND,a.GSDM,a.YSDWDM,a.M1,a.M2,a.M3) as n
on m.ysdwdm=n.ysdwdm
group by n.kjnd,n.gsdm,m.ysdwdm,m.gsmc,n.M1,n.L1,n.M2,n.L2,n.M3,n.L3) Y
order BY ysdwdm
--M是本月数据,L是累计至本月数据。
--如本月没有执行时,连累计至本月数据也没有,如果本月有执行了,本月与累计数据都正确。
--怎么改一下,使本月没执行,就显示累计数据出现呢?