SUM item between two dates
Posted on 2005-04-15
I am having a hard time trying to get what seems like the EASIEST query in the world to work.
The situation... I have two tables:
1. has daily dates with a daily dividend value
2. has an annual date
I want to create a query that will addup the daily dividends for each daily date that falls in a particalur annual date. So, in other words, I want to add-up daily dividends to get the total amount paid in each year. (I cannot hard code the dates because I have companies in my database with odd fiscal years... the annual datadate is fiscal based)
Here is what I have (slightly edited) and it doesn't work... I have tried so many iterations and I am going nuts.
SELECT annual.datadate, Sum(daily.dailydividend) AS 'totalusdlydiv'
FROM calc_usddlydiv daily, co_ann annual
WHERE daily.gvkey = annual.gvkey AND (daily.gvkey='009818') AND (daily.datadate >= annual.datadate AND daily.datadate < (annual.datadate-365))
GROUP BY annual.datadate
Any insights would be GREATLY appreciated!!! (I assigned a lot of points to this one because I was supposed to have this figured out before the end of the week and it is already Friday night... eek!!)