您好我有tbl_Main
AS_ID KWD
1 Man,Businessman,[Business],Office,confidence,arms crossed,
2 Man,Businessman,Business,[Office],laptop,"corridor",waiting,
3 man,business,mobile phone,[mobile],"phone",
如果我使用搜索搜索[office]
,我没有得到任何结果。
我使用以下查询
select * from tbl_main where KWD like '%,[Office],%'
请帮我解决这个问题。谢谢
答案 0 :(得分:4)
[
时, ]
和LIKE
用于模式匹配(类似于正则表达式),因此您实际搜索的是
WHERE KWD LIKE '%,O,%'
OR KWD LIKE '%,f,%'
OR KWD LIKE '%,i,%'
OR KWD LIKE '%,c,%'
OR KWD LIKE '%,e,%'
您需要转义括号,例如:
SELECT *
FROM (VALUES
(1, 'Man,Businessman,[Business],Office,confidence,arms crossed,'),
(2, 'Man,Businessman,Business,[Office],laptop,"corridor",waiting,'),
(3, 'man,business,mobile phone,[mobile],"phone",')
) t (AS_ID, KWD)
WHERE KWD like '%,\[Office\],%' ESCAPE '\';
<强>附录强>
为了你的价值,你应该规范化你的数据,而不是存储一个分隔的列表,使用一个单独的关系表和外键回到tbl_main
,例如
AS_ID Keyword
-----------------------
1 Man
1 Businessman
1 [Business]
1 Office
1 confidence
1 arms crossed
现在你有了一个简单的查询,它可以利用索引的使用:
SELECT *
FROM ASKeyword
WHERE Keyword = '[Office]';
答案 1 :(得分:0)
试试这个
select * from tbl_main where KWD like '%,[Office],%'