错误#1052。帮我找到MySQL查询中的错误

时间:2016-11-01 08:38:24

标签: mysql sql

table gift[table donor[![table year] 2

我需要找到捐赠超过三次的捐赠者。这就是我到目前为止所拥有的

 select DONOR.DONOR_LNAME as last_name, DONOR.DONOR_FNAME as first_name,    count(GIFT.AMOUNT)as NUM_PAYMENTS
from DONOR join GIFT on DONOR.DONOR_NO= GIFT.DONOR_NO 
group by DONOR_NO 
having count(AMOUNT) >=3

1 个答案:

答案 0 :(得分:1)

您需要在使用Table Aliases AND GROUP BY时指定HAVING

试试这个:

SELECT DONOR.DONOR_LNAME as last_name, DONOR.DONOR_FNAME as first_name, COUNT(GIFT.AMOUNT) as NUM_PAYMENTS
FROM DONOR 
INNER JOIN GIFT ON DONOR.DONOR_NO = GIFT.DONOR_NO 
GROUP BY DONOR.DONOR_NO 
HAVING COUNT(GIFT.AMOUNT) >= 3