英文:
Transpose columns to rows with column header in Oracle
问题
已尝试在Oracle中将列转换为行,但列标题应为第一列的值。
注意:带有WHERE子句的SELECT语句。尝试了PIVOT和UNPIVOT,但不幸的是,我没有获得期望的输出。
它应该转换为
请协助。
英文:
Have tried to convert the columns to rows in oracle but the column headers should be the first column values.
Note: The select statement with WHERE clause. Have tried PIVOT and UNPIVOT but unfortunately I am not getting the desired output.
It should be converted to
Please assist.
答案1
得分: 1
Unpivot, as you said.
Sample data:
SQL> with test (column1, column2, column3) as
2 (select 385, 0, 29 from dual)
Query:
3 select *
4 from test
5 unpivot (value for type in (column1, column2, column3));
TYPE VALUE
COLUMN1 385
COLUMN2 0
COLUMN3 29
SQL>;
英文:
Unpivot, as you said.
Sample data:
SQL> with test (column1, column2, column3) as
2 (select 385, 0, 29 from dual)
Query:
3 select *
4 from test
5 unpivot (value for type in (column1, column2, column3));
TYPE VALUE
------- ----------
COLUMN1 385
COLUMN2 0
COLUMN3 29
SQL>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论