我有一个包含多列的表,如下所示:
+-------+------+------+------+
| Name | col1 | col2 | col3 |
+-------+------+------+------+
| pinki | a | b | c |
+-------+------+------+------+
如何将列转换为行并实现如下输出表-
+-------+-----+
| Name | col |
+-------+-----+
| Pinki | a |
| Pinki | b |
| Pinki | c |
+-------+-----+
测试表-
create table testing(
Name varchar(10),
col1 varchar(10),
col2 varchar(10),
col3 varchar(10));
insert into testing(Name,col1,col2,col3) values ('pinki','a','b','c');
答案 0 :(得分:1)
您可以使用union all
select name, col1 as col from testing
union all
select name, col2 from testing
union all
select name, col3 from testing