直接在SQL里可以处理
select max(case when datepart(dw,timestr)=1 then contentstr end) as sunday ,
max(case when datepart(dw,timestr)=2 then contentstr end) as monday ,
max(case when datepart(dw,timestr)=3 then contentstr end) as tuesday ,
max(case when datepart(dw,timestr)=4 then contentstr end) as Wednesday ,
max(case when datepart(dw,timestr)=5 then contentstr end) as Thursday,
max(case when datepart(dw,timestr)=6 then contentstr end) as Friday,
max(case when datepart(dw,timestr)=7 then contentstr end) as Saturday
from (select contentstr,timestr, row_number() over(partition by
datepart(dw,timestr) order by id) as dayofweek from ERPWorkRiZhi
where username=@username and timestr BETWEEN @starttime and @endtime) as a group by dayofweek
典型的行转列,搜索一下就有
排序就可以了