Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Unstack operation BigQuery

Is it possible in Big Query to perform an unstack operation such that

Name  Age Height   
John  27   183
Maria 32   169 

to obtain

Name  attr   value 
John  Age     27
John  Height  183
Maria Age     32
Maria Height  169

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can simply UNPIVOT it.

SELECT * FROM (
  SELECT 'John' Name, 27 Age, 183 Height
   UNION ALL
  SELECT 'Maria', 32, 169
) UNPIVOT (value FOR attr IN (Age, Height))

enter image description here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading