将行转列 SQL Server 2015 [英] Transpose row to column SQL server 2015
本文介绍了将行转列 SQL Server 2015的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
需要帮助将数据从行转换为列
Need help to transpose the data from rows to columns
col1 col2 col3
-------------------
d1 d2 d3
结果应该是
col
----
d1
d2
d3
推荐答案
使用交叉应用
;WITH CTE(col1,col2,col3)
AS
(
SELECT 'd1','d2','d3'
)
SELECT col FROM CTE
CROSS APPLY (VALUES(col1),(col2),(col3)) As Dt (col);
结果,看演示:http://rextester.com/LVXO57980
col
---
d1
d2
d3
这篇关于将行转列 SQL Server 2015的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文