I'm writing a query that has me stumped. I work in Delphi, and am using an ADO query with Jet SQL (Access database). I need to know totals for the month in question, and also for the current year. How do I write a subquery to do this? I've tried:
SELECT Q.Manufacturer, Sum(Q.QValue) AS qval
FROM Q
WHERE (((Month([Q.QDate]))=8) AND ((Q.QDate)=2009))
GROUP BY Q.Manufacturer;
Works. Note that I'll use variables for the hard dates later. Now I'd like to add the total value for the year as well.
SELECT Q.Manufacturer, Sum(Q.QValue) AS qval, t1.qmaxtot
(SELECT Q.Manufacturer, max(Q.Qvalue) as Qmaxtot, from Q where [Q.QDate] = 2009 as t1)
FROM Q
WHERE (((Month([Q.QDate]))=8) AND ((Q.QDate)=2009))
GROUP BY Q.Manufacturer;
No go. Seems like it should be simple. Where am I going wrong?
Dave
SELECT Q.Manufacturer, Sum(Q.QValue) AS qval
FROM Q
WHERE (((Month([Q.QDate]))=8) AND ((Q.QDate)=2009))
GROUP BY Q.Manufacturer;
Works. Note that I'll use variables for the hard dates later. Now I'd like to add the total value for the year as well.
SELECT Q.Manufacturer, Sum(Q.QValue) AS qval, t1.qmaxtot
(SELECT Q.Manufacturer, max(Q.Qvalue) as Qmaxtot, from Q where [Q.QDate] = 2009 as t1)
FROM Q
WHERE (((Month([Q.QDate]))=8) AND ((Q.QDate)=2009))
GROUP BY Q.Manufacturer;
No go. Seems like it should be simple. Where am I going wrong?
Dave