BigQuery IF field exists THEN

后端 未结 1 1162
隐瞒了意图╮
隐瞒了意图╮ 2020-12-11 18:17

I\'m running a query over multiple tables unioned together over a particular time range.

In the past, a particular field did not exist in the \"schema\" but about ha

相关标签:
1条回答
  • 2020-12-11 18:55

    Below should give you direction

    SELECT * FROM
    (SELECT * FROM <somewhere w/o my_field>),
    (SELECT * FROM <somewhere with my_field>)
    

    Assuming you have a, b and c as a fields in your original table () - above can be used (see below) if you need to change missing values from NULL to 0:

    SELECT a, b, c, COALESCE(my_field, 0) as my_field
    FROM
    (SELECT * FROM <somewhere w/o my_field>),
    (SELECT * FROM <somewhere with my_field>)
    
    0 讨论(0)
提交回复
热议问题