gpt4 book ai didi

MySQL:SUM() 功能不起作用

转载 作者:行者123 更新时间:2023-11-29 11:53:34 27 4
gpt4 key购买 nike

我试图对通过将其他两列相乘而创建的列求和,但它似乎不起作用。每次尝试输入 SUM(PriceTimesQuantity)

时都会出现错误

任何和所有的帮助都会很棒!

这是我的查询:

select 
OrderedProduct.orderId,
CustOrder.customerId,
CustOrder.orderDate,
OrderedProduct.paidPrice * OrderedProduct.qtyOrdered as PriceTimesQuantity
from OrderedProduct
join CustOrder
on CustOrder.orderId=OrderedProduct.orderId
where orderDate between '2014-01-01' and '2014-12-31'
group by orderDate

最佳答案

您应该只在 select 中包含 group by 或聚合函数中的列。因此,没有诸如 orderId 之类的列。

这可能更接近您想要做的事情:

select co.orderDate, 
sum(op.paidPrice * op.qtyOrdered) as PriceTimesQuantity
from OrderedProduct op join
CustOrder co
on co.orderId = op.orderId
where co.orderDate between '2014-01-01' and '2014-12-31'
group by co.orderDate;

您的具体错误是您无法引用同一 select 子句中定义的别名。

关于MySQL:SUM() 功能不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33597810/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com