This is for a class I'm taking but I'm stumped at how to do this specific question.
The question is:
In which years did the total donated exceed the goal for the year.
The tables are:
YEAR
year(pk), yeargoal
GIFT
amount, year(pk), donorno(pk)
DONOR
donorno(pk), dlname, dfname, dphone, dstate, dcity
I know I need to sum the amount and group it by year to get a yearly total. My problem is how do I compare this number to the yeargoal number. I can hard code a number in and get a statement that works with that number, but I can't get a statement that will compare each years sum to the goal for each year. Everything I have tried just gives me an error.
My hard coded statement that works is:
select year.year
from year, gift
where year.year = gift.year
group by year.year
having sum(amount) > 5000;
What I need to be able to do is replace 5000 with yeargoal, but that gives me an error and does not work. Any help you guys can offer is appreciated.
The question is:
In which years did the total donated exceed the goal for the year.
The tables are:
YEAR
year(pk), yeargoal
GIFT
amount, year(pk), donorno(pk)
DONOR
donorno(pk), dlname, dfname, dphone, dstate, dcity
I know I need to sum the amount and group it by year to get a yearly total. My problem is how do I compare this number to the yeargoal number. I can hard code a number in and get a statement that works with that number, but I can't get a statement that will compare each years sum to the goal for each year. Everything I have tried just gives me an error.
My hard coded statement that works is:
select year.year
from year, gift
where year.year = gift.year
group by year.year
having sum(amount) > 5000;
What I need to be able to do is replace 5000 with yeargoal, but that gives me an error and does not work. Any help you guys can offer is appreciated.