Skip to Content
avatar image
Former Member

Transform table using sql statements in SAP HANA

Hallo,

I posted this question yesterday and it has been deleted with a comment, failed to search, there were many blogs which i have gone through which were done using hana modeler. whereas i need to write the same in SQL.

I am very new to hana environment. I was introduced to write sql quaries to retrieve data from tables.

I have a table in SAP HANA environment with an Id and the items that were ordered by the IDs.

Table is as follows:

|CustomerID| Items |
|Customer1| Item 1|
|Customer1| Item 2|
|Customer1| Item 3|
|Customer1| Item 4|
|Customer1| Item 5|
|Customer2| Item 1|
|Customer2| Item 3|
|Customer2| Item 6|

I would like to transform the table as follows:

|CustomerID| Item 1| Item 2| Item 3| Item 4| Item 5| Item 6|
|Customer1|1|1|1|1|1|0|
|Customer2|1|0|1|0|0|1|

I would like to write a function or procedure that does the task by iterating over the distinct items, as the length of the distinct items column varies according to requirement.

Any help is very much appreciated!

Thank you!

SQL
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

0 Answers