D
d_delphi
Unregistered / Unconfirmed
GUEST, unregistred user!
SELECT ta1.物料编号,单位,SUM(sum1-sum2+sum3) sum7,sum4,sum5,sum6,SUM(sum1-sum2+sum3+sum4-sum5+sum6) sum8,单价,SUM((sum4-sum5+sum6)*单价) sum9 FROM 物料资料 ta1 left JOIN (SELECT isnull(sum(数量),0) sum1,物料编号 FROM 入成品主 INNER JOIN 入成品从 on (入成品主.入库单号=入成品从.入库单号1) group by 物料编号)ta2 on ta1.物料编号=ta2.物料编号
left JOIN (SELECT isnull(sum(数量),0) sum2,物料编号 FROM 送成品主 INNER JOIN 送成品从 ON (送货单号=送货单号1) group by 物料编号)tb2 on ta1.物料编号=tb2.物料编号
left JOIN (SELECT isnull(sum(数量),0) sum3,物料编号 FROM 报损单主 INNER JOIN 报损单从 ON (报损单号=报损单号1) group by 物料编号)tb3 on ta1.物料编号=tb3.物料编号
left JOIN (SELECT isnull(sum(数量),0) sum4,物料编号 FROM 入成品主 INNER JOIN 入成品从 ON (入库单号=入库单号1) group by 物料编号)tb4 on ta1.物料编号=tb4.物料编号
left JOIN (SELECT isnull(sum(数量),0) sum5,物料编号 FROM 送成品主 INNER JOIN 送成品从 ON (送货单号=送货单号1) group by 物料编号)tb5 on ta1.物料编号=tb5.物料编号
left JOIN (SELECT isnull(sum(数量),0) sum6,物料编号 FROM 报损单主 INNER JOIN 报损单从 ON (报损单号=报损单号1) group by 物料编号)tb6 on ta1.物料编号=tb6.物料编号
group by ta1.物料编号,物料规格,单位,sum4,sum5,sum6,单价,备注
如果把上面的SUM(sum1-sum2+sum3) sum7,SUM(sum1-sum2+sum3+sum4-sum5+sum6) sum8,SUM((sum4-sum5+sum6)*单价) sum9,去掉就可以正常执行,为什么,怎么样做才可以?
left JOIN (SELECT isnull(sum(数量),0) sum2,物料编号 FROM 送成品主 INNER JOIN 送成品从 ON (送货单号=送货单号1) group by 物料编号)tb2 on ta1.物料编号=tb2.物料编号
left JOIN (SELECT isnull(sum(数量),0) sum3,物料编号 FROM 报损单主 INNER JOIN 报损单从 ON (报损单号=报损单号1) group by 物料编号)tb3 on ta1.物料编号=tb3.物料编号
left JOIN (SELECT isnull(sum(数量),0) sum4,物料编号 FROM 入成品主 INNER JOIN 入成品从 ON (入库单号=入库单号1) group by 物料编号)tb4 on ta1.物料编号=tb4.物料编号
left JOIN (SELECT isnull(sum(数量),0) sum5,物料编号 FROM 送成品主 INNER JOIN 送成品从 ON (送货单号=送货单号1) group by 物料编号)tb5 on ta1.物料编号=tb5.物料编号
left JOIN (SELECT isnull(sum(数量),0) sum6,物料编号 FROM 报损单主 INNER JOIN 报损单从 ON (报损单号=报损单号1) group by 物料编号)tb6 on ta1.物料编号=tb6.物料编号
group by ta1.物料编号,物料规格,单位,sum4,sum5,sum6,单价,备注
如果把上面的SUM(sum1-sum2+sum3) sum7,SUM(sum1-sum2+sum3+sum4-sum5+sum6) sum8,SUM((sum4-sum5+sum6)*单价) sum9,去掉就可以正常执行,为什么,怎么样做才可以?