[英]Convert column into rows in oracle
I have table structure as below, Need the output as mentioned below 我有如下表结构,需要输出如下
Table : 表:
A B
CUSTOMER_TYPE_ID 4
CUSTOMER_TYPE_ID 3
CUSTOMER_TYPE_ID 2
CUSTOMER_TYPE_ID 1
CUSTOMER_TYPE_ID 0
Answer : 答:
'4','3','2','1','0'
How to do it? 怎么做?
As described, this isn't a pivot but aggregate string concatenation. 如前所述,这不是关键,而是聚合字符串连接。 The Oracle function is
LISTAGG()
: Oracle函数是
LISTAGG()
:
select listagg(b, ',') within group (order by b desc) as b
from t
group by a;
EDIT: 编辑:
If you want single quotes around the values: 如果要在值周围使用单引号:
select listagg('''' || b || '''', ',') within group (order by b desc) as b
from t
group by a;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.