S
sum_z_x
Unregistered / Unconfirmed
GUEST, unregistred user!
SELECT gprk_2.dddh, gprk_2.pmgg, gprk_2.color, gprk_2.dw, SUM(gprk_2.sl) AS rsl,
SUM(gpck_2.sl) AS csl FROM gprk_2 left OUTER JOIN gpck_2 ON gprk_2.dddh = gpck_2.dddh AND gprk_2.pmgg = gpck_2.pmgg AND gprk_2.color = gpck_2.color AND gpck_2.zt = 'zcc' WHERE (gprk_2.zt = 'zcc') AND (YEAR(gprk_2.rq) = YEAR(GETDATE())) AND (MONTH(gprk_2.rq) >= 9) AND (gprk_2.dh <> '') AND (30 <= DATEDIFF(dd, gprk_2.rq, GETDATE())) GROUP BY gprk_2.dddh, gprk_2.pmgg, gprk_2.color, gprk_2.dw ORDER BY gprk_2.dddh
我的目的是要把表gprk_2,的入库数量(sl),按单号(dddh),品名(pmgg),颜色(color),单位(dw)来和计。然后在算出gpck_2的出库总数量。条件是和gprk_2的单号,品名,颜色一样的。里面还有一些时间条件。但是我用上面那样写它会出现一个情况就是只要
GROUP BY gprk_2.dddh, gprk_2.pmgg, gprk_2.color, 有两条或两条以上的记录它的sum(sl)的值就会比实际的大两倍。这是为什么啊。要怎么改或是要怎么样写才正确啊。
SUM(gpck_2.sl) AS csl FROM gprk_2 left OUTER JOIN gpck_2 ON gprk_2.dddh = gpck_2.dddh AND gprk_2.pmgg = gpck_2.pmgg AND gprk_2.color = gpck_2.color AND gpck_2.zt = 'zcc' WHERE (gprk_2.zt = 'zcc') AND (YEAR(gprk_2.rq) = YEAR(GETDATE())) AND (MONTH(gprk_2.rq) >= 9) AND (gprk_2.dh <> '') AND (30 <= DATEDIFF(dd, gprk_2.rq, GETDATE())) GROUP BY gprk_2.dddh, gprk_2.pmgg, gprk_2.color, gprk_2.dw ORDER BY gprk_2.dddh
我的目的是要把表gprk_2,的入库数量(sl),按单号(dddh),品名(pmgg),颜色(color),单位(dw)来和计。然后在算出gpck_2的出库总数量。条件是和gprk_2的单号,品名,颜色一样的。里面还有一些时间条件。但是我用上面那样写它会出现一个情况就是只要
GROUP BY gprk_2.dddh, gprk_2.pmgg, gprk_2.color, 有两条或两条以上的记录它的sum(sl)的值就会比实际的大两倍。这是为什么啊。要怎么改或是要怎么样写才正确啊。