为Volusion进行SQL导出并获得导致冻结的错误"第2步(共3步) - 打开Recordset"。
SELECT
od.ProductCode
, SUM(od.Quantity) AS 'Total Units Sold'
, SUM(od.TotalPrice) AS 'Total Payment Received'
, SUM(ISNULL(od.Vendor_Price, 0) * od.Quantity) AS 'Total Cost'
, SUM(od.TotalPrice) / SUM(od.Quantity) AS 'Average Price'
, ((SUM(od.TotalPrice) - SUM(ISNULL(od.Vendor_Price, 0) * od.Quantity)) / SUM(od.TotalPrice)) AS 'Average Margin'
FROM OrderDetails AS od
LEFT JOIN Orders AS o
ON o.OrderID = od.OrderID
LEFT JOIN Customers AS c
ON c.CustomerID = o.CustomerID
WHERE c.CustomerID >= 23
AND c.CustomerID <> 24
AND o.Orderstatus <> 'cancelled'
AND c.AccessKey <> 'A'
AND o.OrderDate BETWEEN '2/28/2015 0:00' AND '5/28/2015 23:59'
AND o.Orderstatus NOT LIKE '%Returned'
GROUP BY
od.ProductCode
ORDER BY SUM(od.Quantity) DESC
完全感到困惑,但我已经确定导致问题的一行:
, ((SUM(od.TotalPrice) - SUM(ISNULL(od.Vendor_Price, 0) * od.Quantity)) / SUM(od.TotalPrice)) AS 'Average Margin'
如果删除该行,则返回正常。
感谢任何帮助。
谢谢,
编辑: OrderDetails中有很多列,但有三个列是:
Quantity,Vendor_Price,TotalPrice
答案 0 :(得分:0)
您的查询中没有语法错误。 正如你所说,错误正在进行中
, ((SUM(od.TotalPrice) - SUM(ISNULL(od.Vendor_Price, 0) * od.Quantity))
/ SUM(od.TotalPrice)) AS 'Average Margin'
只有两种可能性
列名拼写错误。但是上面提到的所有列也都使用了早期的列。好吧
下一个问题可能是在这里发生分裂。零分割可能是一个问题。校验和(od.TotalPrice)总是非零。