创建数据表,插入数据等
create table test
(name varchar(10),
fruit varchar(20))
insert into test values ('小明','苹果雪糕');
insert into test values ('小明','西瓜饮料');
insert into test values ('小明','香蕉面包');
insert into test values ('小明','香蕉蛋糕');
insert into test values ('小红','苹果雪糕');
insert into test values ('小红','香蕉面包');
insert into test values ('小王','苹果雪糕');
执行:
select count(distinct a.name) from
(select * from test where fruit like '%苹果%') a,
(select * from test where fruit like '%香蕉%') b
where a.name=b.name
结果: