ERROR: SQL showing total quantity sold from product table and using RIGHT JOIN problem

ERROR: SQL showing total quantity sold from product table and using RIGHT JOIN problem

显示产品 table 的总售出数量。显示产品代码、描述、单位、数量。使用正确的连接。按销量最高的产品排序。

这是我的作品。这是什么问题

SELECT  sd.prodCode, SUM(sd.quantity) "total_quantity", p.prodCode, p.description, p.unit
FROM salesDetail sd
RIGHT JOIN product p 
ON p.prodCode = sd.prodCode
GROUP BY sd.prodCode
ORDER BY SUM(sd.quantity);

错误信息 SELECT 子句、HAVING 子句或 ORDER BY 子句中指定的以“UNIT”开头的表达式未在 GROUP BY 子句中指定,或者它在 SELECT 子句、HAVING 子句或 ORDER BY 中带有列函数且未指定 GROUP BY 子句的子句..

如错误提示:

"UNIT" specified in a SELECT clause, HAVING clause, or ORDER BY clause is not specified in the GROUP BY clause

您需要按 每个 字段对数据进行分组,您在 SELECT 语句中使用 而不是 函数(如 SUM()AVG()COUNT())。

像这样:

SELECT  sd.prodCode, p.prodCode, p.description, p.unit, SUM(sd.quantity) "total_quantity"
FROM salesDetail sd
RIGHT JOIN product p 
ON p.prodCode = sd.prodCode
GROUP BY sd.prodCode, p.prodCode, p.description, p.unit
ORDER BY SUM(sd.quantity);