C
Chris
I need some help writing this query. This should be simple, yet I can't get
it to work as I want. I have a simple database to keep track of incidents.
I need a count of the number of incidents each month (which I have) and for
each month I need the average number of incidents for the previous 6 months
(this is where I need help).
Ex data:
IncidentMonth CountofIncidents 6MoAvgIncidents
Oct-02 16 -
Nov-02 12 -
Dec-02 15 -
Jan-03 21 -
Feb-03 7 -
Mar-03 12 13.83333333
Apr-03 10 12.83333333
May-03 15 13.33333333
Jun-03 18 13.83333333
Jul-03 25 14.5
Aug-03 16 16
Sep-03 16 16.66666667
Oct-03 19 18.16666667
Nov-03 10 17.33333333
Dec-03 12 16.33333333
Here is my SQL:
SELECT Format([IncidentDate],"yyyy") AS SortbyYear,
Format([IncidentDate],"mm") AS SortbyMonth, Format([IncidentDate],"mmm-yy")
AS IncidentMonth, Count(Incidents.Category) AS CountOfIncidents, "HelpHere"
AS 6MoAvgIncidents
FROM Incidents
GROUP BY Format([IncidentDate],"yyyy"), Format([IncidentDate],"mm"),
Format([IncidentDate],"mmm-yy"), "HelpHere"
ORDER BY Format([IncidentDate],"yyyy"), Format([IncidentDate],"mm"),
Format([IncidentDate],"mmm-yy");
Thanks in advance for any help offered!
it to work as I want. I have a simple database to keep track of incidents.
I need a count of the number of incidents each month (which I have) and for
each month I need the average number of incidents for the previous 6 months
(this is where I need help).
Ex data:
IncidentMonth CountofIncidents 6MoAvgIncidents
Oct-02 16 -
Nov-02 12 -
Dec-02 15 -
Jan-03 21 -
Feb-03 7 -
Mar-03 12 13.83333333
Apr-03 10 12.83333333
May-03 15 13.33333333
Jun-03 18 13.83333333
Jul-03 25 14.5
Aug-03 16 16
Sep-03 16 16.66666667
Oct-03 19 18.16666667
Nov-03 10 17.33333333
Dec-03 12 16.33333333
Here is my SQL:
SELECT Format([IncidentDate],"yyyy") AS SortbyYear,
Format([IncidentDate],"mm") AS SortbyMonth, Format([IncidentDate],"mmm-yy")
AS IncidentMonth, Count(Incidents.Category) AS CountOfIncidents, "HelpHere"
AS 6MoAvgIncidents
FROM Incidents
GROUP BY Format([IncidentDate],"yyyy"), Format([IncidentDate],"mm"),
Format([IncidentDate],"mmm-yy"), "HelpHere"
ORDER BY Format([IncidentDate],"yyyy"), Format([IncidentDate],"mm"),
Format([IncidentDate],"mmm-yy");
Thanks in advance for any help offered!