Group records by month

compu

Registered User.
Local time
Today, 02:25
Joined
Jul 18, 2012
Messages
22
Hi everyone

I would just like to know if it is possible to group Months together: this is what i have did so far :

Code:
SELECT Count(Source.ID) AS CountOfID, Clusters.Cluster_Desc, Department.Dept_Desc, DatePart('m',Source.Day_Month_Year) AS [Month], Source.Original_Source, Source.Headline, Source.Issue, Source.Analysis, Source.Action
FROM Source INNER JOIN (Department INNER JOIN (Clusters INNER JOIN Cluster_Dept ON Clusters.Cluster_ID = Cluster_Dept.Cluster_ID) ON Department.Dept_ID = Cluster_Dept.Dept_ID) ON Source.ID = Cluster_Dept.ID
GROUP BY Clusters.Cluster_Desc, Department.Dept_Desc, Source.Original_Source, Source.Headline, Source.Issue, Source.Analysis, Source.Action, Source.Day_Month_Year;

out of all the things in the world , this has stumped me :banghead::(
 
It is possible to group data by month. If your Day_Month_Year field is a date field, you could use the month(datefield) function to extract the month number rather than the datepart() function. Along those lines, since the month() function exists, the word month is a reserved word in Access so I would suggest renaming your field name [month] to something else.

If your data spans more than one year, only grouping by month will group records no matter what the year, so if you want to separate the data by year as well as month, you will need to utilize the year() function in your query.

It sounds like you may not be getting the data you expect from your query. If so, it might be the result of the other fields you have included since having those causes SQL to group by those as well so you may end up with more granular data then you had hoped.
 

Users who are viewing this thread

Back
Top Bottom