问题描述
我有个表,里面有个字段叫content,现在有6个关键词(限行,道路,交警,设卡,指挥,拥堵),我想查content中包含其中任意两个关键词的记录。 问题补充:有没有用一条sql语句解决的方法啊?【●】景天 写道
解决方案
抛个破砖先.create table AAA(name varchar2(10), content varchar2(20))select a.*,a.rowid from AAA a;insert into AAA (NAME, CONTENT) values ('1', 'ACA');insert into AAA (NAME, CONTENT) values ('2', 'B');insert into AAA (NAME, CONTENT) values ('3', 'CA');insert into AAA (NAME, CONTENT) values ('4', 'CCC');insert into AAA (NAME, CONTENT) values ('5', 'DDD');insert into AAA (NAME, CONTENT) values ('6', 'CBA');select name, count(name) from (select * from AAA where content like '%A%' union all select * from AAA where content like '%B%' union all select * from AAA where content like '%C%' union all select * from AAA where content like '%D%') a group by NAMEhaving count(name) >= 2;
解决方案二:
建议写个存储过程吧。。。