【发布时间】:2020-09-21 19:27:28
【问题描述】:
我有一个用于存储库存的表,在显示库存时我想做一些计算,并运行一个返回值的子查询,我将在一些计算中使用。
我的出发点是这样的:
SELECT [lineID]
,[SKUNumber]
,[ContainerNumber]
,[UnitsEaches]
,ISNULL((select Sum(QTY) from AllocatedInventory
Where AllocatedInventory.SKUNumber = Inventory.SKUNumber),0) as 'Allocated'
,[Bay]
,[Level]
,[Position]
,[VCP]
,[UnitWeight]
,[Comments]
,[DateReceived]
FROM [dbo].[Inventory]
我要做的第一件事是从 UnitsEaches 中减去子查询返回的分配量来计算可用库存。当我尝试使用 Allocated 添加 SUM 函数时,我收到一条错误消息,提示 Allocated 列无效。
完成排序后,我需要通过将可用库存除以 VCP 来计算主纸箱。
【问题讨论】:
-
样本数据和期望的结果会有很大帮助。
标签: sql sql-server sum subquery