SUM with constraint involving a different field
Posted on 2010-01-04
I have a report that I am trying to create that provides a couple different Totals that are derived based on conditions found in another field and can't seem to figure out how I can correctly put them into one query. I also want to be able to group these by the month and year.
The information comes from a timesheet table that has the id, date, hours and category. I want to do a query similar to the following:
SELECT id, Month(date), Year(date), (SUM(hours) WHERE category=1) as Total1, (SUM(hours) WHERE category=2) as Total2
GROUP BY Year(date), Month(date)
Any assistance would be greatly appreciated...