我有一个小例子表temp.ty: 从这个表我只想提取的行,其中ipc不存在于not_ipc(而且其中exclude不存在other_classes),这似乎相当straigtforward。但是,以下查询返回零结果:
temp.ty
ipc
not_ipc
exclude
other_classes
SELECT * FROM temp.ty where not ipc contains not_ipc
如果我repclacenot_ipc与例如'G01N 33'它不工作,要么但如果我更换not_ipc与'G01N'它工作得很好。
'G01N 33'
'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 | | +-----+------------+---------+-----------+----------------------+---+