Home > Back-end >  Tranpose Col Values to Col Headers
Tranpose Col Values to Col Headers

Time:10-28

I have a table like below:

table A

And, I want the field values as col headers like below: enter image description here

I tried using PIVOT function of bigQuery but that didn't work. Can anyone guide me on how to achieve this? Thanks

CodePudding user response:

Pivot is the appropriate function to use in this case. Try the following:

select *
from (select * except(field_id) from sample_data)
pivot (max(field_value) for field in ('name', 'age', 'gender', 'email', 'contact', 'address', 'state', 'city'))

It produces

enter image description here

  • Related