0

I want to set all record in one line with seperated by , after GroupBy

My input:

+ --------- + -------------- +
| Name      | Phone Number   |
+ --------- + -------------- +
| John      | 1234567        |
| John      | 1472583        |
| John      | 3698521        |
| John      | 7896541        |
+ --------- + -------------- +

Output I want

+ --------- + -------------------------------+
| Name      |           Phone Number         |
+ --------- + -------------------------------+
| John      | 1234567,1472583,3698521,7896541|
+ --------- + -------------------------------+
  • 1
    Possible duplicate of [How to retrieve two columns data in A,B format in Oracle](https://stackoverflow.com/questions/12145379/how-to-retrieve-two-columns-data-in-a-b-format-in-oracle) and [Concatenate and group multiple rows in Oracle](https://stackoverflow.com/questions/12558509/concatenate-and-group-multiple-rows-in-oracle) – Caramiriel Jul 10 '19 at 14:46

1 Answers1

0

You are looking for listagg():

select name, listagg(phone_number, ', ') within group (order by phone_number) as phone_numbers
from t
group by name;
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786