重问数据拆分
上次在http://topic.csdn.net/u/20100303/16/ab7e7c23-26e7-45ec-b2e2-a364ea6912b7.html
问过一次
但发现不按照SELECT A.ID, A.item, A.bz_qty, A.mdate, max(c.qq1)-NZ(Sum(B.bz_qty),0) AS QQ,
iif(max(c.qq1)-NZ(Sum(B.bz_qty),0) -(a.bz_qty)>0,'ok',max(c.qq1)-NZ(Sum(B.bz_qty),0) -(a.bz_qty)) AS QQ1
FROM (TT1 AS A LEFT JOIN TT1 AS B ON A.[item] = B.[item] AND A.ID>B.ID)
LEFT JOIN (SELECT A1.item, Sum(A1.[order_qty]) AS QQ1
FROM A1
GROUP BY A1.item
) c on A.[item] = c.[item]
GROUP BY A.ID, A.item, A.bz_qty, A.mdate
order by
A.ID, A.item
排布则会提示出现from语句错误
出现空格改变后在还原至以前的排布也一样提示from语句错误
不知道是怎么回事
有表A1:
型号 物料 交货数量
LH020 A 50
LH031 C 250
LH040 C 500
LH020 B 50
LH020 A 50
表A2:
编号 批号 型号 物料 计划量
1 JC02 LH020 A 100
1 JC02 LH020 B 100
2 JC03 LH031 C 300
3 JC04 LH040 C 400
4 JC05 LH020 A 50
4 JC05 LH020 B 50
5 JC09 LH040 C 100
想得到表:
编号 批号 型号 物料 交货总数 领出总数 欠料数
1 JC02 LH020 A 100 100 OK
1 JC02 LH020 B 50 100 -50
2 JC03 LH031 C 250 300 -50
3 JC04 LH040 C 500 400 OK
4 JC05 LH020 A 0 50 -50
4 JC05 LH020 B -50 50 -100
5 JC09 LH040 C 100 100 OK
------解决方案--------------------
SELECT A.ID, A.item, A.bz_qty, A.mdate, max(c.qq1)-NZ(Sum(B.bz_qty),0) AS QQ,
iif(max(c.qq1)-NZ(Sum(B.bz_qty),0) -(a.bz_qty)>0,'ok',max(c.qq1)-NZ(Sum(B.bz_qty),0) -(a.bz_qty)) AS QQ1
FROM (TT1 AS A LEFT JOIN TT1 AS B ON A.[item] = B.[item] AND A.ID>B.ID)
LEFT JOIN
(SELECT A1.item, Sum(A1.[order_qty]) AS QQ1 FROM A1 GROUP BY A1.item ) c on A.[item] = c.[item]
GROUP BY A.ID, A.item, A.bz_qty, A.mdate
order by A.ID, A.item
没有问题