日期:2014-05-18 浏览次数:20662 次
select a.入库单位名称,b.入库年份,sum(a.入库金额),sum(b.已付款金额) sum(case when b.已付款金额 is null then a.入库金额 else 0 end) from 表1 a left join 表2 b on a.入库单位编号=b.入库单位编号 and year(a.入库日期)=convert(int,left(b.入库年份,4)) group by a.入库单位名称,b.入库……
------解决方案--------------------
select a.入库单位名称,b.入库年份,sum(a.入库金额),sum(b.已付款金额), sum(case when b.已付款金额 is null then a.入库金额 else 0 end) from 表1 a left join 表2 b on a.入库单位编号=b.入库单位编号 and year(a.入库日期)=convert(int,left(b.入库年份,4)) group by a.入库单位名称,b.入库……
------解决方案--------------------
try:
SELECT a.rk_dwid,a.rk_dw as dwmc,year(a.rk_date) as 入库年份,SUM(a.rk_spzj) as fkje,SUM(b.yfl_fkje) as yfje,SUM(a.rk_spzj)-SUM(b.yfl_fkje) as 未付金额 FROM rkd a left join ysyfjl b on a.rk_dwid=b.gg_id and YEAR(a.rk_date)=convert(int,LEFT(b.yfl_nf,4)) and b.yfl_type='gys' and b.yfl_mark='付款' where a.rk_style='正常入库' and a.rk_fbbj='000' group by a.rk_dwid,a.rk_dw,year(a.rk_date)