select max(case rownumber % 3 when 2 then wsshowname end)as ws1,
max(case rownumber % 3 when 1 then wsshowname end) as ws2,
max(case rownumber % 3 when 0 then wsshowname end) as ws3
from
(select row_number() over(order by [columnn]) as rownumber,wsshowname,columnn from @table) A
group by (rownumber+2)/3 --重要的是這句
参考链接:https://www.cnblogs.com/ywkpl/archive/2008/06/03/1213149.html