【问题标题】:unexpected behaviour of Google BigQuery WHERE NOT list CONTAINS stringGoogle BigQuery WHERE NOT list CONTAINS string 的意外行为
【发布时间】:2015-08-02 00:26:28
【问题描述】:

我有一个小示例表temp.ty: 从这个表中,我只想提取not_ipc 中不存在ipc 的行(以及other_classes 中不存在exclude 的行),这似乎相当简单。然而,以下查询返回零结果:

SELECT * FROM temp.ty where not ipc contains not_ipc

如果我将not_ipc 替换为例如'G01N 33' 它也不起作用如果我将not_ipc 替换为'G01N' 它就可以正常工作。

我已经尝试了通配符和 LIKE 操作以及 STRING() 函数的变体,但到目前为止我还无法管理。 我有一种强烈的感觉,我错过了什么,但我想不通。

【问题讨论】:

    标签: sql google-bigquery contains


    【解决方案1】:

    这是一个示例查询:

    select * from
    (select 'G01N 33/55' as ipc, 'G01N 34' as not_ipc),
    (select 'G01N 33/55' as ipc, 'G01N 33' as not_ipc),
    (select 'G01N 33/55' as ipc, string(null) as not_ipc)
    where not ipc contains not_ipc or not_ipc is null
    

    返回:

    +-----+------------+---------+---+
    | Row |    ipc     | not_ipc |   |
    +-----+------------+---------+---+
    |   1 | G01N 33/55 | G01N 34 |   |
    |   2 | G01N 33/55 | null    |   |
    +-----+------------+---------+---+
    

    这是另一个:

    select * from
    (select 'G01N 33/55' as ipc, 'G01N 33' as not_ipc, 'C08K 3/08' as exclude, 'C08K 3/08,C08K 77/02' as other_classes),
    (select 'G01N 33/55' as ipc, 'G01N 34' as not_ipc, string(null) as exclude, 'C08K 3/08,C08K 77/02' as other_classes),
    (select 'G01N 33/55' as ipc, 'G01N 33' as not_ipc, string(null) as exclude, string(null) as other_classes),
    (select 'G01N 33/55' as ipc, 'G01N 36' as not_ipc, string(null) as exclude, string(null) as other_classes),
    (select 'G01N 33/55' as ipc, string(null) as not_ipc, 'C08K 3/08' as exclude, string(null) as other_classes)
    where (not ipc contains not_ipc or not_ipc is null) and (not other_classes contains exclude or exclude is null or other_classes is null)
    

    返回:

    +-----+------------+---------+-----------+----------------------+---+
    | Row |    ipc     | not_ipc |  exclude  |    other_classes     |   |
    +-----+------------+---------+-----------+----------------------+---+
    |   1 | G01N 33/55 | G01N 34 | null      | C08K 3/08,C08K 77/02 |   |
    |   2 | G01N 33/55 | G01N 36 | null      | null                 |   |
    |   3 | G01N 33/55 | null    | C08K 3/08 | null                 |   |
    +-----+------------+---------+-----------+----------------------+---+
    

    【讨论】:

    • @Guus 好的,您也应该将其标记为已解决。
    猜你喜欢
    • 1970-01-01
    • 2021-08-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-30
    • 2013-11-22
    • 1970-01-01
    相关资源
    最近更新 更多