SELECT A.[公司],A.[商品],A.[清单数量],A.[单价],A.[金额],B.[申请数量],C.[入库数量] FROM
(SELECT T1.[公司],T1.[商品],SUM(T1.[清单数量]) AS [清单数量],SUM(T1.[单价]) AS [单价],SUM(T1.[金额]) AS [金额]
FROM [设备清单] T1
GROUP BY T1.[公司],T1.[商品]) A
LEFT JOIN
(SELECT T2.[公司],T2.[商品],SUM(T2.[申请数量]) AS [申请数量] FROM [采购申请] T2
GROUP BY T2.[公司],T2.[商品]) B
ON A.[公司]=B.[公司] AND A.[商品]=B.[商品]
LEFT JOIN
(SELECT T3.[公司],T3.[商品],SUM(T3.[入库数量]) AS [入库数量] FROM [采购入库] T3
GROUP BY T3.[公司],T3.[商品]) C
ON A.[公司]=C.[公司] AND A.[商品]=C.[商品]
改成这样完美,谢谢大佬 |