我有2代表這樣,內加入與含有條件
表1
Id Locations
-- ---------
1 India, Australia
2 US , UK
表2
Table2Id Location
-------- --------
101 Italy
102 UK
103 Hungary
104 India
我需要內部連接這兩個表在條件下,如果表2中的Locations
包含表1中的Location
字段。其結果就會像
Id Table2Id Location Locations
-- -------- -------- ---------
1 104 India India, Australia
2 102 UK US , UK
我想是這樣
Select t1.id,
t2.Table2Id,
t1.Locations,
t2.Location
From Table1 t1
Inner join Table2 t2 On CONTAINS(t1.Locations, t2.Location)
但contains
第二個參數應該是一個字符串。它不允許在那裏提供列名。
我不能在查詢中使用temptable
或variable
。由於此查詢需要在名爲ExactTarget
的電子郵件營銷活動工具上運行,因此不支持temptable
和variables
。
任何幫助將不勝感激。謝謝。
您的查詢無法正常工作,請參閱:http://sqlfiddle.com/#!3/90a6b/1 – Rimas 2014-09-23 05:38:26
@Rimas好眼睛。 '','+在聯接中替換(table1.locations,',',',')+','like'%,'+ table2.location +',%''可能看起來很難看,但可能會訣竅 – zedfoxus 2014-09-23 05:46:54
@zfus非常感謝你的答案.. – 2014-09-23 05:50:48