【问题标题】:BigQuery IS NOT NULL where condition not workingBigQuery 在条件不起作用的情况下不为空
【发布时间】:2021-10-21 19:07:48
【问题描述】:

我正在尝试使用以下命令在 BigQuery 中创建一个表。在我的原始数据集中,“customDimensions”是一个包含 2 个子字段的嵌套列:值和索引。在我的查询中,我想要一个 where 条件来过滤掉带有 customDimensions.value IS NOT NULL 的记录。但是,在我的输出数据中,仍然有 PCF_CUST_ID 为空的记录。为什么我的 where 条件不起作用?

create table `putput_folder.output_data` as
select visitId
      ,(select value FROM t.customDimensions where index = 4) AS PCF_CUST_ID
from `input_folder.input_data_*` as t, UNNEST(customDimensions) as customDimensions
where _TABLE_SUFFIX between '20210101' and '20210131' and customDimensions.value is not null
order by visitId;

【问题讨论】:

    标签: google-bigquery nested where-clause


    【解决方案1】:

    考虑以下几点:

    select
      visitId,
      cd.value as PCF_CUST_ID
    from `input_folder.input_data_*` as t
    left join unnest(customDimensions) cd
    where _TABLE_SUFFIX between '20210101' and '20210131'
      and cd.index = 4 and cd.value is not null
    order by visitId
    

    您的原始查询选择了每个visitId,无论它们是否有index=4

    【讨论】:

    • 非常感谢它的工作原理!
    猜你喜欢
    • 2017-05-03
    • 1970-01-01
    • 2011-01-04
    • 2023-03-06
    • 2015-05-26
    • 2013-12-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多