日期:2014-05-17 浏览次数:20530 次
select a.编码,a.名称,
(select sum(金额) from b where b.编码=a.编码) as 金额1,
(select sum(金额) from c where c.编码=a.编码) as 金额2,
(select sum(金额) from b where b.编码=a.编码)-(select sum(金额) from c where c.编码=a.编码) as 金额2
from a
select a.编码,a.名称,sum(b.金额) as 金额1,sum(c.金额) as 金额2,
sum(isnull(b.金额,0))- sum(isnull(c.金额,0)) as 金额3
from a
left join b on b.编码=a.编码
left join c on c.编码=a.编码
group by a.编码,a.名称