简体   繁体   中英

Categorize data using sql

I have data in the below format in status table (newstat) with unique identifer id

 

 id status status1
----- 
 1 COMP ACC REQ 
 2 COMP DECL 
 3 ACR  ACC REQ 
 4 ACR  CANCEL 
 5 ACW     DECL  
 6 ACW     ACC REQ

.....

using sql query (oracle 11g) i need the data to be in nested format

 
 COMP    ACC REQ, DECL
 ACR     ACC REQ, CANCEL
 ACW     ACC REQ, DECL

i have tried code using LISTAGG(), wm_concat

tried using sql but all are generating errors.

ORA-00904: "WM_CONCAT": invalid identifier

Doesn't this work?

select status, listagg(status1, ', ') within group (order by id) as statuses
from t
group by status
order by min(id);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM