0

I have a table as follows

|Cutomers|Orders|Items| |Cutomer1|Order1|Item1| |Cutomer1|Order1|Item2| |Cutomer1|Order1|Item3| |Cutomer1|Order2|Item1| |Cutomer1|Order2|Item3| |Cutomer1|Order2|Item4| |Cutomer2|Order1|Item6| | . | . | . | | . | . | . | | . | . | . |

I want to have the following table, seems like easy but i have no clue how to deal with it.

|Customers|Items| |Customer1|Item1| |Customer1|Item2| |Customer1|Item3| |Customer1|Item4| |Customer2|Item6| | . | . | | . | . | | . | . |

Any suggestions are very much appreciated!

2 Answers 2

3

I think this would suffice

select  distinct Customers, Items
from    YourTable
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Stefano, I was thinking too complex :)
1

From Oracle 11gR2, the LISTAGG clause should do the trick:

SELECT customers,
       LISTAGG(items, ',') WITHIN GROUP (ORDER BY items)
FROM YOUR_TABLE
GROUP BY customers;

try this, it might work

you can also wm_concat

SELECT customers, wm_concat(items) as item
FROM   table
GROUP BY customers;

it might also work

for my sql,

select  distinct customers, items from tablename

1 Comment

the last one wins the race, its simple and i didnt got this idea :) I was thinking too complex. thanks Ashok

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.