0

Table:

|COL_1  | COL_2  | COL_3
|------ | ------ |--------
|A      |A1      | 1
|A      |A2      | 3
|A      |A3      | 2
|B      |B1      | 2
|B      |B2      | 1

COL_3 for order.

I want to get this:

A   |A1,A3,A2
B   |B2,B1

Any advice or suggestions will be appreciated. Thanks.

Pure SQL script, please.


Update My answer below is for Oracle 11, but get an error in Oracle 10g:

ORA-00923: FROM keyword not found where expected

For Oracle 10g, what's the solution?
Thanks.

Community
  • 1
  • 1
youngzy
  • 397
  • 2
  • 13

1 Answers1

0

For Oracle 11 use this:

select col_1
     , listagg(col_2, ', ') within group (order by col_3) as col_new
from tbl_tmp
group by col_1;

Run here : SQL Fiddle

Refrence:https://stackoverflow.com/questions/17501418/oracle-string-aggregation

Community
  • 1
  • 1
youngzy
  • 397
  • 2
  • 13