【发布时间】:2018-05-01 06:02:54
【问题描述】:
如何将一个子字符串匹配到另一个子字符串。我似乎只能ilike 搜索其中一个,不能同时搜索子字符串。
给定表格:
对话
string
-------------------
Hi, my name is dan
结构
structure
----------
his name is / my name is
hello, my / you are
how are you?
预期输出:
string | structure
-------------------------------
Hi, my name is dan | his name is / my name is
尝试:
两个ilike 模糊匹配:
select string, structure from dialog left join structures on ('%' || string || '%' ilike '%' || structure || '%');
两个模糊的ilike 匹配OR:
select string, structure from dialog left join structures on (string ilike '%' || structure || '%') or (structure ilike '%' || string || '%');
两个输出:
string | structure
-------------------------------
Hi, my name is dan |
【问题讨论】:
-
his name is / my name is -
为了强调蒂姆的评论,“他的名字是”不匹配“我的名字是”,所以你不能做匹配。时期。您需要更加认真地思考您的数据以及您想要完成的任务。
标签: sql postgresql join substring