sql - 连接的两个表上的子字符串匹配
问题描述
如何对一个子字符串匹配到另一个子字符串执行连接。我似乎只能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 |
解决方案
如果结构实际上匹配,您可以使用正则表达式:
select string, structure
from dialog d left join
structures s
on string ~ replace(string, ' / ', '|');
当然,这不适用于示例数据,因为字符串实际上并不匹配。
这也表明您的结构实际上应该是正则表达式。
推荐阅读
- python - 如何使用 pdfkit 将图像添加到 wkhtmltopdf 中的标题?
- python - 如何在 Qt5 中调整父级大小后调整方形子级小部件的大小?
- python - 使用 psycopg2 和 POSTGRESQL 在 Python 中为 SELECT 查询的可选参数更正函数定义
- python - 有没有办法打包一个简单的 Python 项目并让它通过 Internet 执行安装
- cloud - Openstack——如何使用云资源
- reactjs - Differents drawer navigator for each user type in React Native
- wxwidgets - wxwidget 构建失败 - windows - mingw - mingw32-make: *** [..\..\lib\gcc_dll\wxmsw313u_gcc_custom.dll] 错误 1
- r - 使用 igraph 创建二分图
- android - 一个 Textview 在 ConstraintLayout 中与另一个重叠
- c# - XtraReports 表上的条件分页符