How do you group weekly data into quarterly data in SQL?
I'd like the code below to return the columns selected in the statement but sum up sales by quarter rather than return weekly data.
My code:
select
pz.PriceZoneID,
pz.Name,
es.ClientDepartmentID,
es.DepartmentName,
es.ClientCategoryID,
es.CategoryName,
es.ClientSubCategoryID,
es.SubCategoryName,
es.ClientProductID,
es.ProductName,
ash.Sales as Units,
ash.price * ash.Sales as CashSales,
ash.Cost,
CAST(ash.date as Date) as Date
from aggregatedsaleshistory as ash
join v_EnterpriseStructure as es on es.ProductSID = ash.ProductSID
join PriceZone as pz on pz.PriceZoneID = ash.PriceZoneID
WHERE es.SubCategoryName = 'Yogurt'
GROUP BY
pz.PriceZoneID,
pz.Name,
es.ClientDepartmentID,
es.DepartmentName,
es.ClientCategoryID,
es.CategoryName,
es.ClientSubCategoryID,
es.SubCategoryName,
es.ClientProductID,
es.ProductName,
ash.Cost,
ash.Date
The output has the weekly dates in the last column. So my question is how can I group the weekly data into quarters? I'd paste a sample below here, but I'm not sure how to provide sample data here? A sample I'd just pasted came out in a strange format when I saved the edit!
Thanks in advance?