【发布时间】:2020-10-23 12:16:24
【问题描述】:
我在 Postgres 11 中有下表:
col1 col2 col3 col4
1 trial_1 ag-270 ag
2 trial_2 ag ag
3 trial_3 methotexate (mtx) mtx
4 trial_4 mtx mtx
5 trial_5 hep-nor-b nor-b
我想在整个 col3 列中搜索 col4 的每个值。如果 col4 中的值存在于 col3 中,我想保留其他行,否则应排除该行。
期望的输出是:
col1 col2 col3 col4
1 trial_1 ag-270 ag
2 trial_2 ag ag
3 trial_3 methotexate (mtx) mtx
4 trial_4 mtx mtx
我无法对此进行任何尝试,因为我还无法找到解决方案。
【问题讨论】:
-
为什么最后一行(带有
col1 = 5的那一行)被排除在外?'nor-b'是'hep-nor-b'的子字符串。 -
nor-b 在 'col3' 中不作为一个完整的字符串存在(作为一个子字符串存在)
-
是的,
'nor-b'(col4) 是'hep-nor-b'(col3) 的最后 (5) 个字符。 -
或者你的意思是(完全)平等?但是只有
col1 = 2和col1 = 4的行才会出现在结果中。 -
是的,我的意思是完全平等
标签: sql postgresql filter exists