34,587
社区成员
发帖
与我相关
我的任务
分享
create table ta (asd varchar(16))
insert into ta select
'asd' union select
'12412' union select
'123' union select
'123啊师父' union select
'士大夫234' union select
'wr2143' union select
'345saf34523'
go
select
col1 = max(case when id%5 = 0 then asd else null end ),
col2 = max(case when id%5 = 1 then asd else null end),
col3 = max(case when id%5 = 2 then asd else null end),
col4 = max(case when id%5 = 3 then asd else null end),
col5 = max(case when id%5 = 4 then asd else null end)
from (select id = (select count(1)
from ta
where asd <= b.asd) ,*
from ta b) a
group by id/5
/*
col1 col2 col3 col4 col5
---------------- ---------------- ---------------- ---------------- ----------------
NULL 123 123啊师父 12412 345saf34523
asd wr2143 士大夫234 NULL NULL
*/
drop table ta