一条sql语句如何模糊查询多个字符串
比如我要把content字段里包含 aaaa、bbb、ccc、dddd 这几个字符串的数据排除掉
应该咋写
------解决思路----------------------
SELECT * FROM TABLE WHERE content LIKE '%aaaa%' AND content LIKE '%bbb%' AND content LIKE '%ccc%' AND content LIKE '%dddd%'
------解决思路----------------------
最笨的方法:
select content from A where content not like 'aaaa' and content not like 'bbb' and content not like 'ccc'
------解决思路----------------------
直接:
select * from table where content not like '%aaaa%' orcontent not like '%bbb%' orcontent not like '%ccc%' orcontent not like '%dddd%';
或者麻烦些:
select * from table where id not in (select id from table where content like '%aaaa%' and content like '%bbb%' and content like '%ccc%' and content like '%dddd%');