VerySource

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
123
返回列表 发新帖
楼主: westevil

求一SQL语句的写法.

[复制链接]

0

主题

3

帖子

4.00

积分

新手上路

Rank: 1

积分
4.00
发表于 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]
回复

使用道具 举报

2

主题

18

帖子

13.00

积分

新手上路

Rank: 1

积分
13.00
 楼主| 发表于 2020-8-8 01:30:01 | 显示全部楼层
楼上强人呀。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

快速回复 返回顶部 返回列表