我试图通过乘以另外两列来创建我创建的列,但它似乎并没有起作用。每当我尝试输入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
答案 0 :(得分:1)
您应该只在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
子句中定义的别名。