我有一种情况,当字符串值作为表中的列值存储在语句中时,我需要将该字符串值与另一个表连接,其中字符串值有助于识别要包含的行。
ID Name Value
1 Jack I work in Amazon and I like to read.
2 Mary I work in Facebook and prefer to play Basketball.
3 Klay I play football and work at Google.
4 Josh I work for UN and I like travelling.
5 Jane I am currently a student and I play Hockey.
Value Include
Basketball Y
Hockey Y
Football Y
Read N
Travelling N
因此,从表1中我需要找到字符串值,然后将其连接到此表以确定它是“Y”值还是“N”值。有没有办法将这些值与表1分开。
ID Name Include
1 Jack N
2 Mary Y
3 Klay Y
4 Josh N
5 Jane Y
答案 0 :(得分:0)
不会那么高效,但它不能像表格的布局那样得到帮助。只需加入一个LIKE运算符。
SELECT *
FROM Table1
JOIN Table2
ON Table1.Value LIKE '%' + Table2.Value '%'
WHERE Table2.Include = 'Y'