declare
@aa varchar(20)
set @aa= CONVERT(varchar(100), GETDATE(), 23)
--//日
print @aa+' 0:00:00.000'
print @aa+' 23:59:59.999'
--//周
print CONVERT(varchar(100), DATEADD(wk, DATEDIFF(wk,0,getdate()), 0), 23)+' 0:00:00.000'
print CONVERT(varchar(100), DATEADD(wk, DATEDIFF(wk,0,getdate()), 6), 23)+' 23:59:59.999'
--//月
print CONVERT(varchar(100), DATEADD(m, DATEDIFF(m,0,getdate()), 0), 23)+' 0:00:00.000'
print CONVERT(varchar(100), DATEADD(m, DATEDIFF(m,0,getdate()), 30), 23)+' 23:59:59.999'
select distinct (userid),sum(score) as SumScore from ph where endTime between @aa+' 0:00:00.000' and @aa+' 23:59:59.999' group by userid order by SumScore desc
select distinct (userid),sum(score) as SumScore from ph where endTime between CONVERT(varchar(100), DATEADD(wk, DATEDIFF(wk,0,getdate()), 0), 23)+' 0:00:00.000' and CONVERT(varchar(100), DATEADD(wk, DATEDIFF(wk,0,getdate()), 6), 23)+' 23:59:59.999' group by userid order by SumScore desc
select distinct (userid),sum(score) as SumScore from ph where endTime between CONVERT(varchar(100), DATEADD(wk, DATEDIFF(wk,0,getdate()), 0), 23)+' 0:00:00.000' and CONVERT(varchar(100), DATEADD(wk, DATEDIFF(wk,0,getdate()), 6), 23)+' 23:59:59.999' group by userid order by SumScore desc