So I am trying to get the sum of all "scriptamount" for each "practice" for the previous month in one field, and then add two more fields. One for 2 months ago and then one for 3 months ago. This will allow me to see the growth for each "practice" over the past 3 months. However, I am stuck on the first step. The below subquery returns the the sum of "scriptamount" for the entire month. How can I have this query return the sum for each practice instead of for the entire month? Thanks in advance!
SELECT SourceScriptsByMonth.Practices,
(SELECT sum(scriptamount)
FROM sourcescriptsbymonth
WHERE month(datefilled) = month(date())-1
AND year(datefilled)=year(date()))
AS [Last month]
FROM SourceScriptsByMonth
GROUP BY practices;
SELECT SourceScriptsByMonth.Practices,
(SELECT sum(scriptamount)
FROM sourcescriptsbymonth
WHERE month(datefilled) = month(date())-1
AND year(datefilled)=year(date()))
AS [Last month]
FROM SourceScriptsByMonth
GROUP BY practices;