|
发表于 2020-8-6 15:30:01
|
显示全部楼层
SELECT A_x.ModelInfoNO, z.[ModelNO], z.[TradeName], z.[EnscapMode], z.[Quality], z.[BatchNO],
A_y.ShopWarehouseNO,
ISNULL(InStockInfo.InStock_Count, 0) AS InStock_Count,
ISNULL(OutStockInfo.OutStock_Count, 0) AS OutStock_Count
FROM
(
SELECT DISTINCT ModelInfoNO FROM [InStockOrder Details]
union
SELECT DISTINCT ModelInfoNO FROM [OutStockOrder Details]
)
A_x,
(
SELECT DISTINCT InShopWarehouseNO AS ShopWarehouseNO FROM [InStockOrders]
union
SELECT DISTINCT OutShopWarehouseNO FROM [OutStockOrders]
)A_y,
(
SELECT A.ModelInfoNO,B.InShopWarehouseNO,SUM(A.Quantity) as InStock_Count
FROM [InStockOrder Details] A, [InStockOrders] B
WHERE A.[InStockOrderNO]=B.[NO]
GROUP BY A.ModelInfoNO, B.InShopWarehouseNO
) InStockInfo,
(
SELECT A.ModelInfoNO,B.OutShopWarehouseNO,SUM(A.Quantity) as OutStock_Count
FROM [OutStockOrder Details] A, [OutStockOrders] B
WHERE A.[OutStockOrderNO]=B.[NO]
GROUP BY A.ModelInfoNO, B.OutShopWarehouseNO
) OutStockInfo,
ShopWarehouseInfo y1,
ModelsInfo z,
WHERE InStockInfo.ModelInfoNO=A_x.ModelInfoNO AND InStockInfo.InShopWarehouseNO = A_y.ShopWarehouseNO AND
OutStockInfo.ModelInfoNO = A_x.ModelInfoNO AND OutStockInfo.OutShopWarehouseNO = A_y.ShopWarehouseNO AND
y1.[ID] = A_y.ShopWarehouseNO AND A_x.ModelInfoNO=z.[NO] |
|