大家好,我写了一个查询来显示数量的总和,如下所示,没有 group by
SELECT ISNULL(SUM(VUItems.Quantity), 0) AS OrderQty
FROM VUItems
0.00
当使用group by
不显示0.00
可能是什么问题时,这将返回相同的查询
SELECT ISNULL(SUM(VUItems.Quantity), 0) AS OrderQty
FROM VUItems
GROUP BY SKU,
SalesOrderNo
为什么我需要的是我将有一个表格,该表格将包含保存数量这是我为显示订购的数量或用户输入的数量而编写的内容,如下所示
SELECT VU1.*,
VU1.Quantity - (SELECT ISNULL(SUM(VU2.Quantity), 0) AS OrderQty
FROM VU2
WHERE VU1.SKU = VU2.SKU
AND VU1.SalesOrderNo = VU2.SalesOrderNo
GROUP BY SKU) AS orderedQuantity
FROM VU1
没有 group by 它会orderedQuantity
根据需要显示,但 group by 它会显示null