Pivot from columns to rows?
I have a table that looks like that:
ID | completion_Rate - step1 | completion_Rate - step2 | completion_Rate - step3 |
---|---|---|---|
id1 | 0 | 29 | 54 |
id2 | 0 | 22 | 76 |
I want to Pivot it to that:
ID | step_number | completion_Rate |
---|---|---|
id1 | 1 | 0 |
id1 | 2 | 29 |
id1 | 3 | 54 |
id1 | 1 | 0 |
id2 | 2 | 22 |
id3 | 3 | 76 |
I know we don't have Pivot function in Vertica, but maybe there is a smart way to do it?
(If not, I'll take it a step back, the original table looks like that:
id | completion_rates |
---|---|
id1 | 0_29_54 |
id2 | 0_22_76 |
So if there is another way to "explode" this string into rows, that doesn't use split part to convert to columns first it will also help me.
)
I tried splitting into columns, but now I don't find a way to pivot
0
Answers
Hi Yarden,
Please try this:
Hi Yarden,
You can use the function string_to_array to convert your original data to the array datatype.
Query is the same than @mosheg 's: