日期:2014-05-18 浏览次数:20366 次
select a.名称,sum(a.数量) as A表总数量,isnull(sum(c.数量),0) as c表总数量 from a left join c on a.名称=c.名称
------解决方案--------------------
select a.名称, isnull(b.数量,0) B表总数量, isnull(c.数量,0) C表总数量 from A left join (select 名称,sum(数量) as 数量 from B group by 名称) b on a.名称=b.名称 left join (select 名称,sum(数量) as 数量 from C group by 名称) c on a.名称=c.名称
------解决方案--------------------
select 名称,
sum( bnum ) as b表总数量,
sum( cnum ) as c表总数量
from (
select a.名称, isnull(b.数量, 0) as bnum, isnull(c.数量, 0 ) as cnum
from a left jion b on b.名称 = a.名称
left jion c on c.名称 = a.名称 ) temp_t
group by 名称