我使用以下查询对输出进行排序。它适用于某些情况但不是全部。输出图片给出。有什么建议吗?任何备用请。
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))
答案 0 :(得分:1)
为什么要在获得年份和月份前提取一周?
我想你想要:
ORDER BY MIN(ad.xDate) DESC
这将按每行的任意日期排序。