【发布时间】:2016-04-12 18:56:44
【问题描述】:
我正在尝试总结各个价格并使用折扣逻辑。
SELECT O.OrderID,
if(C.IsClubMember & OrderNumber % 10 = 0, 0.5 * Sum(I.ItemPrice), Sum(I.ItemPrice)) as Price,
0.07*Price as Tax, Price + Tax as Total
FROM Orders as O JOIN ItemPriceView as I
ON O.OrderID = I.OrderID JOIN Customer as C
ON O.CustomerID = C.CustomerID
GROUP BY OrderID
我收到一个错误:
Error Code: 1054. Unknown column 'Price' in 'field list'
编写查询的正确方法是什么?
【问题讨论】:
-
您不能在
select子句中重复使用别名。 -
所以我需要将整个逻辑子句复制粘贴到选择的每个部分吗?我需要做一个中间视图来保持价格,然后再做税收和总计吗?
-
您可以复制/粘贴 select 子句中的逻辑
标签: mysql sql sql-function