asp.net c# SQL 按日期循环显示数据

SQL查询得到以下数据Date data1 data2-------------------------------01 10 1102 12 1303 14 1504 16 1705 18 1906 20 2107 22 2308 24 2509 26 27如何将以上数据按照日期循环排列呢,如下: Sun Mon Tue Wed Thu Fri Sat TTL-------------------------------------------------------------------------Date 01 02 03 04 05 06 07data1 10 12 14 16 18 20 22 112 data1 11 13 15 17 19 21 23 119 ------------------------------------------------------------------------- Date 08 09 data1 24 26 50data1 25 27 52--------------------------------------------------------------------------请高人指点,拜谢!不一定要通过SQL实现,通过前台代码实现也可以。
2026年09月28日 17:07
有3个网友回答
网友(1):

直接在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

网友(2):

典型的行转列,搜索一下就有

网友(3):

排序就可以了