SELECT 订单明细表.订单ID, 订单.最后交货日期, 订单明细表.型号, Sum(订单明细表.订货数量) AS 订货数量, Sum(nz([发货数量],0)) AS 已发货数量, [订货数量]-[已发货数量] AS 欠发货数量
FROM 订单 INNER JOIN (订单明细表 LEFT JOIN 发货明细表 ON (订单明细表.产品代码 = 发货明细表.产品代码) AND (订单明细表.订单ID = 发货明细表.订单编号)) ON 订单.订单ID = 订单明细表.订单ID
GROUP BY 订单明细表.订单ID, 订单.最后交货日期, 订单明细表.型号
ORDER BY 订单明细表.型号;