select datename(weekday,CAST([CompletedTime] AS date)) WeekNum,
CAST([CompletedTime] AS date) AS 'Date' ,
SUM(case when OrderStatus=2 and IsDeleted=0 then PlatformAmount else 0 end) as PlatformAmount,
SUM(case when OrderStatus=2 and IsDeleted=0 then AgentAmount else 0 end) as AgentAmount,
SUM(case when OrderStatus=2 and IsDeleted=0 then TenantAmount else 0 end) as TenantAmount
from QYNET_Order where datediff(week,CompletedTime,getdate()-1)=0
group by CAST([CompletedTime] AS date)
order by Date
其中 CompletedTime就是时间,下面是查询结果