How to aggregate in Sql

Viewed 33

I would like to aggregate the below ID's and extract datetime into a month column.

My sql query seems to not aggregate when I bring in the date because the date field has date time.

This is dummy data.

Select Id,Area_Name,first_name,surname,Action_start_time,Month(Action_Start_time) [Month], count(id) Volume
From [Car dealership].[dbo].[Car Calls]
Group by Area_Name,first_name,surname,Id,Action_start_time;

enter image description here

This is what I get. Even when I remove the Action Start time. I still dont get the aggregation to work.

1 Answers

Why don't you just remove the Action_start_time from the select?

Use the Month(Action_start_time) function inside the group by clause.

Select Id,Area_Name,first_name,surname,Month(Action_Start_time) [Month], count(id) Volume From [Car dealership].[dbo].[Car Calls]
Group by Area_Name,first_name,surname,Id,Month(Action_start_time);
Related