user5400828 user5400828 - 1 month ago 12
MySQL Question

ERROR #1052. Help me find the error in MySQL query

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

I need to find the donors that have donated over three times. This is what I have so far

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

Answer

You need to specify the Table Aliases when you use GROUP BY AND HAVING.

Try this:

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
Comments