以下日期排序查询有什么问题
Whats wrong with the following date sort query
我正在使用以下查询对输出进行排序。它在某些情况下有效,但并非全部。给出的输出图片。任何建议为什么?请任何替代。
Select
'playing' As activity,
max(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(wk, ad.xDate)
Order By
YEAR(datepart(wk, ad.xDate)) DESC, MONTH(datepart(wk, ad.xDate)) DESC, DAY(datepart(wk, ad.xDate))
为什么要在获取年月之前提取周?
我想你想要:
ORDER BY MIN(ad.xDate) DESC
这将按每行的任意日期排序。
我正在使用以下查询对输出进行排序。它在某些情况下有效,但并非全部。给出的输出图片。任何建议为什么?请任何替代。
Select
'playing' As activity,
max(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(wk, ad.xDate)
Order By
YEAR(datepart(wk, ad.xDate)) DESC, MONTH(datepart(wk, ad.xDate)) DESC, DAY(datepart(wk, ad.xDate))
为什么要在获取年月之前提取周?
我想你想要:
ORDER BY MIN(ad.xDate) DESC
这将按每行的任意日期排序。