求余额

SELECT ph, sum(slye) from
(
select ph,decode(SSSL,null,0,SSSL)SLYE from BB_MJ_KCRKD2_TB where to_char(ywrq,'yyyymm')<'201308' and instr(djzt,'审核')>0
UNION ALL
SELECT ph,decode(SFSL,null,0,-SFSL)SLYE
FROM BB_MJ_KCCKD2_TB where to_char(ywrq,'yyyymm')<'201308' and instr(djzt,'审核')>0 )T group by ph having sum(slye)!=0

posted @ 2015-05-02 15:13  大虎1  阅读(132)  评论(0编辑  收藏  举报