1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

  2. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[SQL] How to Unpivot a Struct in BigQuery?

Discussão em 'Outras Linguagens' iniciado por Stack, Setembro 13, 2021.

  1. Stack

    Stack Membro Participativo

    I have a table with an ID and then a struct. I want to turn each element of the struct into a new row with the struct field name being a value in the column Period and the value being the structures value. See table below

    Query that generated the table:

    [​IMG]

    Current data

    [​IMG]

    I tried this:

    SELECT * FROM `business-analytics-workbench.RAW.User_Activity` as UA
    UNPIVOT(Activity FOR PERIOD in (Last_7_Days,Last_14_Days,Last_30_Days,Last_90_Days,First_Date_AEST,Last_Date_AEST))


    But I get this error "Unrecognized name: Last_7_Days at [3:33]"

    Continue reading...

Compartilhe esta Página