SELECT 订单表.OrderNo, 订单表.CPBH, Sum(订单表.SL) AS 订单总数 FROM 订单表 GROUP BY 订单表.OrderNo, 订单表.CPBH;
收货查询:
SELECT 送货表.OrderNO, 送货表.CPBH, Sum(送货表.SL) AS 收货总数 FROM 送货表 GROUP BY 送货表.CPBH, 送货表.OrderNO;
用LEFT JOIN 把订单结存数列出来
SELECT 订单查询.OrderNo, 订单查询.CPBH, 订单查询.订单总数, 收货查询.收货总数, (nz(订单查询.订单总数)-nz(收货查询.收货总数)) AS 结余订单数
FROM 订单查询 LEFT JOIN 收货查询 ON (订单查询.CPBH=收货查询.CPBH) AND (订单查询.OrderNo=收货查询.OrderNO);
[attach]33472[/attach]
出来的结果却不是我想要的
改成 INNER JOIN 方式
SELECT 订单查询.OrderNo, 订单查询.CPBH, 订单查询.订单总数, 收货查询.收货总数, (nz(订单查询.订单总数)-nz(收货查询.收货总数)) AS 结余订单数
FROM 订单查询 INNER JOIN 收货查询 ON (订单查询.OrderNo = 收货查询.OrderNO) AND (订单查询.CPBH = 收货查询.CPBH);