Quick SQL query for several months

SELECT DISTINCT MonthName(Month([Date])) AS [Month], tblSupportCalls.System, Count(tblSupportCalls.System) AS [Total for System], Year([Date]) AS [Year]
FROM tblSupportCalls
WHERE (((tblSupportCalls.Date) Between Now() And Now()-7) AND ((tblSupportCalls.System) In ('Career Campus','E-PEEP')) AND ((tblSupportCalls.StartTime) Is Not Null) AND ((Hour([StartTime]))>=7))
GROUP BY tblSupportCalls.System, tblSupportCalls.Date;

Whenever I indicate that he gives me several months, for example:

July
July
July

I want him to just say July only 1 time, and I can’t understand why the field ever repeats on different days. I just want to say:

MONTH | System | Total Systems | Year

what I'm watching

> MONTH | System | Total Systems | Year
> July      CC           2         2010
> July      CC           7         2010
> July      CC           9         2010
> July      EE           1         2010
> July      EE           2         2010

Must be:

MONTH | System | Total Systems | Year
July      CC          18         2010
July      EE          03         2010
+3
source share
2 answers

You want to group your year and month instead tblSupportCalls.Date.

...
GROUP BY tblSupportCalls.System, Year([Date]), Month([Date]);
+3
source

You still group the results by date, though (not by month). I think you want something like this:

GROUP BY tblSupportCalls.System, Year ([tblSupportCalls.Date]), [Month([tblSupportCalls.Date]);

I think you still want to group by year, so July 2010 appears in a different row from July 2011.

+1
source

Source: https://habr.com/ru/post/1795610/


All Articles