SQL查询 - 使用带限制的SUM函数进行选择

时间:2015-04-01 00:44:26

标签: mysql sql sum

enter image description here

我正在尝试查询列出总数为PTNG_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错误。

1 个答案:

答案 0 :(得分:1)

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;