我有一个包含
等结果的表格Donna F. Carreras|Alexander J. Deborde|John Ford|Marjorie M. Lee| Crystal C Zhu
176 | 246 | 312 | 502 | 19969
我希望它显示为:
176 Donna F. Carreras
246 Alexander J. Deborde
312 John Ford
502 Marjorie M. Lee
19969 Crystal C Zhu
答案 0 :(得分:2)
在SQL Server中,您可以应用UNPIVOT
功能:
select value, col
from yourtable
unpivot
(
value
for col in ([Donna F. Carreras], [Alexander J. Deborde],
[John Ford], [Marjorie M. Lee], [Crystal C Zhu])
) un
或者您可以使用UNION ALL
查询:
select [Donna F. Carreras] value, 'Donna F. Carreras' col
from yourtable
union all
select [Alexander J. Deborde] value, 'Alexander J. Deborde' col
from yourtable
union all
select [John Ford] value, 'John Ford' col
from yourtable
union all
select [Marjorie M. Lee] value, 'Marjorie M. Lee' col
from yourtable
union all
select [Crystal C Zhu] value, 'Crystal C Zhu' col
from yourtable
两者产生相同的结果:
| VALUE | COL |
--------------------------------
| 176 | Donna F. Carreras |
| 246 | Alexander J. Deborde |
| 312 | John Ford |
| 502 | Marjorie M. Lee |
| 19969 | Crystal C Zhu |