gpt4 book ai didi

sql - Oracle 将列显示为行

转载 作者:行者123 更新时间:2023-12-05 00:18:14 24 4
gpt4 key购买 nike

如何通过以下示例将多列转换为行编码?对于解决方案,我检查了许多样本,例如枢轴、解码等,但我没有达到绝对解决方案。

+---------+---------+---------+---------+
| COL_1 | COL_2 | COL_3 | COL_4 |
+---------+---------+---------+---------+

I wanna make columns like this;

+---------+
| COL_1 |
+---------+
| COL_2 |
+---------+
| COL_3 |
+---------+
| COL_4 |
+---------+

最佳答案

也许你想要 unpivot ?

with demo as ( select 1 as col1, 2 as col2, 3 as col3, 4 as col4 from dual )
select * from demo
unpivot
( colvalue for col in (col1, col2, col3, col4) );

COL COLVALUE
---- ----------
COL1 1
COL2 2
COL3 3
COL4 4

4 rows selected.

关于sql - Oracle 将列显示为行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38504172/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com