select COALESCE(a.规格,b.规格,c.规格),COALESCE(a.级别,b.级别c.级别),sum(进库数),sum(出库数),sum(库存数)
from a full join b on a.规格=b.规格 and a.级别=b.级别 full join c
on (a.规格=c.规格 and a.级别=c.级别 ) or (c.规格=b.规格 and c.级别=b.级别 )
group by COALESCE(a.规格,b.规格,c.规格),COALESCE(a.级别,b.级别c.级别)
from a full join b on a.规格=b.规格 and a.级别=b.级别 full join c
on (a.规格=c.规格 and a.级别=c.级别 ) or (c.规格=b.规格 and c.级别=b.级别 )
group by COALESCE(a.规格,b.规格,c.规格),COALESCE(a.级别,b.级别c.级别)
SELECT A.规格,A.级别,ISNULL(sum(进库数),0) 进库数,ISNULL(sum(出库数),0) 出库数,ISNULL(sum(库存数),0) 库存数
FROM A LEFT JOIN B ON A.规格=b.规格 and A.级别=b.级别
LEFT JOIN ON A.规格=c.规格 and a.级别=c.级别
GROUP BY A.规格,A.级别
库存数=sum(ISNULL(库存数,0)) From A,B,C where A.规格*=B.规格 and A.级别*=B.级别
and A.规格*=C.规格 and A.级别*=C.级别
库存数=sum(ISNULL(库存数,0)) From A,B,C where A.规格*=B.规格 and A.级别*=B.级别
and A.规格*=C.规格 and A.级别*=C.级别 GROUP BY A.规格,A.级别