将单列转换为单行 [英] convert single column to single row

查看:97
本文介绍了将单列转换为单行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表,其中包含的数据为

I have a table which contains data as

Data<br />
10<br />
21<br />
35<br />
148<br />
54<br />
74



现在我想将此单列转换为单行,如:



Now i want to convert this single column to single row as:

Data Col1 Col2 Col3 Col4 Col5<br />
10    21   35   148  54   74



我该如何在sql server中做到这一点?



How can i do this in sql server

推荐答案

您可以使用Pivot和Unpivot将行更改为列,反之亦然. SQL 2005+中提供了此功能.

看看 sql-query-convert-columns-into-rows [^ ]
You can use Pivot and Unpivot to change rows into columns and viceversa. This feature is available in SQL 2005+.

Take a look on sql-query-convert-columns-into-rows[^]


在SQL 2005中使用PIVOT运算符可实现此目标

msdn.microsoft.com/en-us/library/ms177410.aspx
stackoverflow.com/questions/.../sql-server-pivot-examples
Use PIVOT operator in SQL 2005 to achieve this

msdn.microsoft.com/en-us/library/ms177410.aspx
stackoverflow.com/questions/.../sql-server-pivot-examples


这篇关于将单列转换为单行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆