Currently writing an sql query on sql server 2008 and have a query which counts the amount of sales in a week, currently my code is grouping by week number however I am wanting to return the first date in the week.
currently it's returning
week number count
1 5
2 3
3 8
what I'm trying to get it to do is
Week Number Date Count
1 1/01/2015 5
2 7/01/2015 3
3 14/01/2015 8
Currently the code I have is
SELECT DATEPART(WK,CAST(a.sale_date AS DATE)), count(a.sale)
from sales a
where a.sale_date >= Dateadd(DAY, Datediff(Day, 0, DATEADD(WEEK, -52, current_timestamp)), 0)
group by DATEPART(WK,CAST(a.sale_date AS DATE))
Any time I try and add the sale_date column it prints out similar to the following
Week Date count
1 1/01/2015 2
1 2/01/2015 1
1 5/01/2015 2
2 7/01/2015 1
2 7/01/2015 2
etc.