[英]How do I make the GROUP BY clause in this query run?
Write a SELECT statement that returns three columns: 编写一个SELECT语句返回三列:
EmailAddress
, OrderID
, and the order total
for each customer
. 每个
customer
EmailAddress
, OrderID
和order total
。
To do this, you can group the result set by the EmailAddress
and OrderID
columns. 为此,您可以按
EmailAddress
和OrderID
列对结果集进行分组。
In addition, you must calculate the order total from the columns in the OrderItems
table. 另外,您必须从
OrderItems
表中的列中计算订单总数。
SELECT c.EmailAddress, oi.OrderID, (oi.ItemPrice * oi.Quantity) -
oi.DiscountAmount
FROM Customers c JOIN Orders o ON c.CustomerID = o.CustomerID
JOIN OrderItems oi ON o.OrderID = oi.OrderID
GROUP BY c.EmailAddress, oi.OrderID
You are looking for GROUP BY
and SUM()
: 您正在寻找
GROUP BY
和SUM()
:
SELECT c.EmailAddress, oi.OrderID,
SUM(oi.ItemPrice * oi.Quantity - oi.DiscountAmount)
FROM Customers c JOIN
Orders o
ON c.CustomerID = o.CustomerID JOIN
OrderItems oi
ON o.OrderID = oi.OrderID
GROUP BY c.EmailAddress, oi.OrderID;
Column must appear in the GROUP BY clause or be used in an aggregate function. 列必须出现在GROUP BY子句中或在聚合函数中使用。 Your column
您的专栏
(oi.ItemPrice * oi.Quantity) - oi.DiscountAmount
does not satisfy this requirement. 不满足此要求。 I assume what you want to do is
我想你想做的是
sum((oi.ItemPrice * oi.Quantity) - oi.DiscountAmount)
? ?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.