cancel
Showing results for 
Search instead for 
Did you mean: 

Challenge #8 How to concatenate multipe rows into single row grouping by a data value

Rasha
Employee
Employee

Hello again,

Given a data set as below:

Rasha_1-1690743359681.png

the data source is attached: Group_Concat_Test.csv 

It has  a column named value that contains a single data per row, And it is required to concatenate these rows grouping by the key column and it should be shown as comma-separated data values.

It should be like that:

Rasha_2-1690743429134.png

Please help me to achieve it 🤷‍♀️ 😀.

1 REPLY 1

RADSr
Captain
Captain

I am certain the ordering of the values can be done, but I've spent longer than I had anticipated just getting this simple select to work: 

 

SELECT "Key", array_join(collect_set("Value"), ',') as VLU

FROM "PivotTest"."PivotTestSource"

group by "Key"

order by key ;

 

I imported the text file ( note: I don't recommend using keywords as column names 😉 ) ran the table, then created an MV using Spark SQL

( I did it in the notebook view so I could test it easily as I went NOTE TO PRODUCT TEAM!

and the results are

 

RADSr_0-1691521138739.png

 

 

-- IncortaOne@PMsquare.com --