How to unpivot any existing raw table?
I want to transpose columns to rows
here I am aware about stack can be used, but i dont want to give hard coded columns names... how this can be done run time (Without passing any hardcoded value of column name in stack command?)
How to get run time columns count & how this columns can be passed in stack?
Table1:
id | p1 | p2 | p3 |
1 | 2.0 | 3.0 | 4.0 |
2 | 10.0 | 15.0 | 20.0 |
select id,
stack(3, 'p1', p1, 'p2', p2, 'p3', p3) as (property,value)
from `db1`.`Table1`