How to avoid datepart to start from new week on ye

2019-08-07 14:50发布

I have an sql query which I am using to get weekly data. It works fine but when the year changes it stops the week on 4 days or whatever and starts a new week for new year. I dont want that. I want it to keep working like like before. Any idea of how to force GROUP BY datepart(week, ad.xDate)

Select 'playing' As activity 
,min(ad.xDate) As xDate
,Isnull(sum(t.TimePerDay),0) As TimePerDay 
From    AllDates As ad With (Nolock) 
Left Join @test As t On ad.xDate = t.date
GROUP BY datepart(week, ad.xDate)   
ORDER BY MIN(ad.xDate)
option (maxrecursion 0)

1条回答
走好不送
2楼-- · 2019-08-07 15:50
GROUP BY
    DATEDIFF(week, 0, ad.xDate)
查看更多
登录 后发表回答