那就再加一层嵌套,已修正!
- SELECT e.产品,e.规格,f.使用部门,f.领用数量,e.累计入库,e.累计出库,e.库存 FROM
- (SELECT c.*,d.累计入库,d.累计出库,d.累计入库-d.累计出库 AS 库存 FROM
- (SELECT 产品,IIF(规格 is null,"",规格) as 规格 FROM [入库$] GROUP BY 产品,规格)c
- LEFT JOIN
- (SELECT a.产品,a.规格,a.累计入库,b.累计出库 FROM
- (SELECT 产品,IIF(规格 is null,"",规格) as 规格,SUM(入库数量) AS 累计入库 FROM [入库$] GROUP BY 产品,规格)a
- LEFT JOIN
- (SELECT 产品,IIF(规格 is null,"",规格) as 规格,IIF(SUM(领用数量) is null,0,SUM(领用数量)) AS 累计出库 from [出库$] GROUP BY 产品,规格)b
- ON a.产品=b.产品 AND a.规格=b.规格)d
- ON c.产品=d.产品 AND c.规格=d.规格)e
- LEFT JOIN
- (SELECT 产品,IIF(规格 is null,"",规格) as 规格,使用部门,SUM(领用数量) as 领用数量 FROM [出库$] GROUP BY 产品,规格,使用部门)f
- ON e.产品=f.产品 AND e.规格=f.规格
- ORDER BY e.产品,e.规格
复制代码
|