BigQuery IF 字段存在 THEN
BigQuery IF field exists THEN
我运行查询在特定时间范围内联合在一起的多个表。
过去,"schema" 中不存在特定字段,但大约在该时间范围的一半时,该字段开始存在并开始填充数据。
有没有办法有条件地 select 如果它存在,否则任意填充一个命名字段的值?
像这样:
SELECT
(CASE WHEN exists(my_field) THEN my_field ELSE "0" END) as "my_field"
FROM <somewhere>
下面应该给你方向
SELECT * FROM
(SELECT * FROM <somewhere w/o my_field>),
(SELECT * FROM <somewhere with my_field>)
假设您在原始 table () 中将 a、b 和 c 作为字段 - 如果您需要将缺失值从 NULL 更改为 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>)
我运行查询在特定时间范围内联合在一起的多个表。
过去,"schema" 中不存在特定字段,但大约在该时间范围的一半时,该字段开始存在并开始填充数据。
有没有办法有条件地 select 如果它存在,否则任意填充一个命名字段的值?
像这样:
SELECT
(CASE WHEN exists(my_field) THEN my_field ELSE "0" END) as "my_field"
FROM <somewhere>
下面应该给你方向
SELECT * FROM
(SELECT * FROM <somewhere w/o my_field>),
(SELECT * FROM <somewhere with my_field>)
假设您在原始 table () 中将 a、b 和 c 作为字段 - 如果您需要将缺失值从 NULL 更改为 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>)