sql - Google BigQuery WHERE NOT 列表包含字符串的意外行为

标签 sql google-bigquery contains

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

SELECT * FROM temp.ty where not ipc contains not_ipc

如果我用 'G01N 33' 替换 not_ipc ,如果我用 替换 not_ipc ,它也不起作用'G01N' 它工作得很好。

我尝试过通配符和 LIKE 操作以及 STRING() 函数的变体,但到目前为止我还无法管理。 我有一种强烈的感觉,我错过了一些东西,但我无法弄清楚。

最佳答案

这是一个示例查询:

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                 |   |
+-----+------------+---------+-----------+----------------------+---+

关于sql - Google BigQuery WHERE NOT 列表包含字符串的意外行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30355055/

相关文章:

SQL Server 审核注销会产生大量读取

sql - Postgres 不允许 localhost 但可以使用 127.0.0.1

google-bigquery - 提前确定分组与分组

ElasticSearch 查询 - 存在但不包含

sql - 将多行和多列值显示为单行多列值

sql - 将外部选择行变量传递给 oracle 中的内部选择

javascript - 如何从 bigquery API 查询 bigquery View

java - 是否可以根据窗口元素的时间戳动态生成 BigQuery 表名?

jquery - 我如何遍历元素中的每个单词然后有条件地换行匹配?

c# - 有没有更好的方法来编写 new List<string> {"a", "b"}.Contains(str)?