基于SQL中另一个表的值从列中提取子字符串
在SQL中(假设ANSI标准SQL),是否可以基于另一个表从一列中提取一个子字符串,然后将该子字符串放入另一列中 下表中的示例:基于SQL中另一个表的值从列中提取子字符串,sql,ansi-sql,redash,Sql,Ansi Sql,Redash,在SQL中(假设ANSI标准SQL),是否可以基于另一个表从一列中提取一个子字符串,然后将该子字符串放入另一列中 下表中的示例: VISITS name summary --------------------------------------------- john visit to London jack hotel in Paris with park visits joe b&b in Paris with ice cream
VISITS
name summary
---------------------------------------------
john visit to London
jack hotel in Paris with park visits
joe b&b in Paris with ice cream
james holidays in London and museums
jason visit in Milan and fashion tour
LOCATIONS
id name
-------------
1 Paris
2 London
3 Milan
4 Berlin
其思想是从摘要
列中提取位置,并输出以下内容:
VISITS
name summary location
---------------------------------------------
john visit to London London
jack hotel in Paris with park visits Paris
joe b&b in Paris with ice cream Paris
james holidays in London and museums London
jason visit in Milan and fashion tour Milan
您可以执行模式匹配:
select v.*, l.name
from visits v
left join locations l on v.summary like concat('%', l.name, '%')
正如jarlh所评论的,ANSI sql具有用于字符串连接的运算符|
,因此,根据您的数据库:
select v.*, l.name
from visits v
left join locations l on v.summary like '%' || l.name || '%'
请用您正在使用的数据库标记您的问题。@GMB我通常会这样做,但在这种情况下我不确定-我使用的是Redash平台,不确定他们使用的是什么标准基于SQL方式:
…“%”|l、 名称| |'%'
。