2016-10-08 87 views
0

我有两个表t1和t3。如果t1字符串出现在t2字符串中,我需要t3具有t1字符串。SQL:将一列的字符串与另一个表列的子串匹配

t1-[mango, apple, Top] 
t2-[{Ate mango}, {it was nice apple},{you are hero}, {apple shares top}] 

如果T1的串t2的子字符串匹配,那么T3将 输出为T3

t3-[mango, apple, , {apple,top}] 

enter image description here

+2

请注意** ** mysql的< > ** Sql Server ** <> ** Postgresql **,所以'TAG'你正在使用的不是全部 –

+0

我删除了数据库标记。请只重新添加适用于您的内容。 – sstan

+1

是的,这里的人需要知道你是否问PostgreSQL,MySQL/MariaDB,MS SQL Server等,然后专家可以解决你的问题:) – SomeDude

回答

0
Select 
SecondCol Result 
From 
(
Select 
Col2 FirstCol, 
UPPER(LISTAGG(Col1, ', ') WITHIN GROUP (ORDER BY Col2)) SecondCol 
From 
(Select Table1.T1 Col1, Table2.T1 Col2 From Table1,Table2 
Where 
Length(REGEXP_SUBSTR(UPPER(Table2.T1), UPPER(Table1.T1)))<>0 
) 
Group By Col2 
); 

Screenshot after executing above Query

相关问题