我正在尝试查询以列出总PNG_PRICE高于7000的PTR_NUM。我正在尝试执行以下操作:

SELECT painter.PTR_FIRSTNAME, painter.PTR_LASTNAME,
SUM(painting.PTNG_PRICE) AS 'TOTAL PAINTING COST'
FROM painter, painting
WHERE painter.PTR_NUM = painting.PTR_NUM
AND SUM(painting.PTNG_PRICE) > 7000
GROUP BY painter.PTR_NUM;


我收到1111错误。

最佳答案

SELECT painter.PTR_FIRSTNAME, painter.PTR_LASTNAME,
SUM(painting.PTNG_PRICE) AS 'TOTAL PAINTING COST'
FROM painter, painting
WHERE painter.PTR_NUM = painting.PTR_NUM
GROUP BY painter.PTR_NUM
HAVING SUM(painting.PTNG_PRICE) > 7000;

关于mysql - SQL查询-使用SUM函数进行限制选择,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29381010/

10-11 02:58