我有一个sql查询,我用它来获取每周数据。它工作正常,但当年份发生变化时,它会在4天或其他任何时间停止一周,并开始新的一周新的一周。我不想那样。我希望它像以前一样继续工作。想知道如何强制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)
答案 0 :(得分:2)
GROUP BY
DATEDIFF(week, 0, ad.xDate)