2016-10-08 83 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

相關問題