Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

listagg with partition by clause

syed haiderJul 6 2018 — edited Jul 12 2018

I'm trying to combine cities based on states.

E.g

cities          states

Chicago     IL

Skokie        IL

Houston     TX

The output should be as follows;

cities                       states

Chicago, Skokie      IL

Houston                   TX

I'm using following code;

select    members,

          companies,

          listagg(cities, ',') within group (order by cities) over (partition by states) as cities,

from      location

This code is giving me an error that "not a group by expression". The reason I'm using partition by clause because I don't want to members and companies.

Any suggestions will be greatly appreciated. Thanks!

This post has been answered by Frank Kulash on Jul 9 2018
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 9 2018
Added on Jul 6 2018
10 comments
7,547 views