Reputation: 107
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?
Upvotes: 1
Views: 1074
Reputation: 1269503
As described, this isn't a pivot but aggregate string concatenation. The Oracle function is 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;
Upvotes: 2