MySQL pivot单行

MySQL pivot单行,mysql,sql,Mysql,Sql,我发现有很多问题可以用另一种方法来解决,但我不能用这种方法来解决 假设我从表中选择了一行,因此我有以下内容: A | B | C | D | E ------------------ 1| 2 | 3 | 4 | 5 我如何在mysql中对其进行透视以创建以下内容: r | c ----- A | 1 ----- B | 2 ----- C | 3 ----- D | 4 ----- E | 5 然后我打算把它放到另一张桌子上 这可能吗?怎么用?我想不出任何办法,在谷歌上也找不到答案 谢谢

我发现有很多问题可以用另一种方法来解决,但我不能用这种方法来解决

假设我从表中选择了一行,因此我有以下内容:

A | B | C | D | E
------------------
 1| 2 | 3 | 4 | 5
我如何在mysql中对其进行透视以创建以下内容:

r | c
-----
A | 1
-----
B | 2
-----
C | 3
-----
D | 4
-----
E | 5
然后我打算把它放到另一张桌子上

这可能吗?怎么用?我想不出任何办法,在谷歌上也找不到答案


谢谢。

如果您的列名是固定的,您可以使用此选项

(样本表)

从so_tmp中选择a、b、c、d、e; 取消PIVOT查询:

select 'a' r, a c from so_tmp
union all
select 'b', b from so_tmp
union all
select 'c', c from so_tmp
union all
select 'd', d from so_tmp
union all
select 'e', e from so_tmp;

如果列名是固定的,则可以使用

(样本表)

从so_tmp中选择a、b、c、d、e; 取消PIVOT查询:

select 'a' r, a c from so_tmp
union all
select 'b', b from so_tmp
union all
select 'c', c from so_tmp
union all
select 'd', d from so_tmp
union all
select 'e', e from so_tmp;

那么你基本上想创建一个数据透视表?那么你基本上想创建一个数据透视表?