MSSQL 查詢結果一列變三列的寫法

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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章