一列变三列的例子:

sql server 一列分多列 sql 一列变多列_d3

select 
max(case rownumber % 3 when 2 then id else null end) as id1,
max(case rownumber % 3 when 2 then [text] else null end) as text1,
max(case rownumber % 3 when 1 then id else null end) as id2,
max(case rownumber % 3 when 1 then [text] else null end) as text2,
max(case rownumber % 3 when 0 then id else null end) as id3,
max(case rownumber % 3 when 0 then [text] else null end) as text3
from 
(select row_number() over(order by [type] desc) as rownumber,[id],[text] from tablename) A
group by (rownumber+2)/3