How to combine multiple row fields in sap hana table

I am using the SAP-HANA database. I have a simple table with two columns whose columns are id, name. The lines are as follows:

1 - tom
1 - harry
1 - jack
2 - larry

I would like to group the strings by id and combine the names in a field and thus get this:

1 - tom, harry, jack
2 - larry

Could you tell me how we can perform this operation in the sap khan? Thanks in advance.

+4
source share
1 answer

If you are using HANA with version 70, you can try the following: -

SELECT ID, STRING_AGG(Name, ',')  AS Names
FROM TAB
GROUP BY ID;

And for more info read this

How to combine a column value from several rows into one column?

+14
source

All Articles