I have been researching this for a while. I have a Dataset below, and I need the desired out out to be in a list of strings. If there is a duplicate Product I want it to go on a seperate row. what the below gets me is all of the customerid and products on one line. I want if there are duplicates make the duplicate on anothe line. Please let me know if there are any questions.
With CustomerData as (
select
ROW_NUMBER() OVER (PARTITION BY customerid ORDER BY Product) rn,
COUNT(*) OVER (PARTITION BY customerid ) cnt
from Customers)
select
ltrim(sys_connect_by_path(customerid,','),','),
ltrim(sys_connect_by_path(Product,','),',') AS Product,
from CustomerData
where rn = cnt
start with rn = 1
connect by prior customerid = customerid
and prior rn = rn1
customerid | CustomerName | Product | date
1 Bob 9 3-14-2016
1 Bob 10 3-14-2016
1 Bob 9 3-12-2016
2 Brad 1 3-14-2016
2 Brad 3 3-14-2016
3 Sam 1 3-14-2016
3 Sam 1 3-12-2016
3 Sam 5 3-14-2016
Desired Output
customerid CustomerName Product
1, 1 BOB, BOB 9, 10
1, BOB 9
2, 2 Brad, Brad 1, 3
3, 3 Sam, Sam 1, 5
3 Sam 1