How to unnest and pivot two columns in BigQuery

前端 未结 3 1245
谎友^
谎友^ 2021-01-27 07:40

Say I have a BQ table containing the following information

| id    | test.name     | test.score    |
|----   |-----------    |------------   |
| 1     | a                 


        
3条回答
  •  梦谈多话
    2021-01-27 08:18

    One option could be using conditional aggregation

    select id, 
           max(case when test.name='a' then test.score end) as a,
           max(case when test.name='b' then test.score end) as b,
           max(case when test.name='c' then test.score end) as c
    from 
    (
    select a.id, t
    from `table` as a,
    unnest(test) as t
    )A group by id
    

提交回复
热议问题