-3

Please help to how to write the Oracle query to get the result
(in 3 seperate columns) like "abcd 1,5,7 xyz" from below table,I want to include COL3 as a seprate column. Please help

 Oracle Database table
    ======================
    col1  |  col2 | col3
    ======================
    ABCD      1     xyz
    ======================
    EDF       3     lmn
    ======================
    ABCD      5     xyz
    ======================
    ABCD      7     xyz
    ======================

    Thanks in advance. :) 

1 Answers1

1
select   col1, listagg(col2, ',') within group (order by col2) as new_col_name
from     table_name
group by col1;
  • Thanks a lot this works coool :) – user3380194 May 12 '16 at 19:48
  • Hi, - If a solution works for you in your situation, it is customary to mark the question as Answered so that volunteers on SO can focus on questions that haven't been answered yet. Cheers! –  May 12 '16 at 23:37
  • Done :) I was trying to mark as an answer, but stackoverflow was not allowing me...., hahah, again thanks for your answer – user3380194 May 13 '16 at 19:19
  • Hi Math guy, I need one more help from you,Please check I have edited my querstion. – user3380194 May 20 '16 at 06:03
  • Please show by way of your example what the output should look like. –  May 20 '16 at 11:38
  • Thanks for reponse @mathGuy, I want to avoid the one column , SELECT LISTAGG(CSP_GROUP, ',') WITHIN GROUP (ORDER BY CSP_GROUP) AS NEW_COL_NAME, UCP_GROUP, RANK,BILLING_ROLE,BBNMS_ROLE,CREATED_USER_ID,UPDATED_USER_ID,UPDATED_TIME_STAMP,SASVP_ROLE FROM UCP_GROUP_MAPPING GROUP BY UCP_GROUP,RANK,BILLING_ROLE,BBNMS_ROLE,CREATED_USER_ID,UPDATED_USER_ID,UPDATED_TIME_STAMP,SASVP_ROLE – user3380194 May 25 '16 at 07:22