sql - 列到 MySql 中行的简单枢轴

标签 sql mysql pivot

我在 mysql 中有下表:

A B C D
1 2 3 4

我想把它变成

<title1> <title2>
A        1
B        2
C        3
D        4

我只发现了复杂的东西,有谁知道一个简单的 staright forward 函数可以做到这一点吗?

最佳答案

select 'A' as title1, a as title2 from table union all
select 'B' as title1, b as title2 from table union all
select 'C' as title1, c as title2 from table union all
select 'D' as title1, d as title2 from table

关于sql - 列到 MySql 中行的简单枢轴,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5078916/

相关文章:

javascript - 如何将数据从 C++ 应用程序传递到 Javascript

sql - 替换 SQL 中字符串中第一次出现的子字符串

MySql 查询(连接)

mysql - 让学生有 2 个不同的限制条件

sql - Postgresql 包含在 where 子句中

mysql - 多条件加入

MySQL 将行转为动态数量的列

python - Pandas :转向真/假,删除列

mysql - SQL从一个表中获取值,用减号排除其他表

java - 如何正确向jpa onetomany join表添加记录