我需要找到捐赠超过三次的捐赠者。这就是我到目前为止所拥有的
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
答案 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