我有一个类似以下的表
table_fruit:
account_id fruit
1 apple
1 banana
2 apple
2 orange
2 banana
3 apple
我正试图列出每个有苹果而没有其他水果的的人
这似乎是一个简单的想法,但它现在已经过时了。。。
您可以将not exists
用作
select * from table_fruit t1
where t1.fruit = 'apple'
and not exists(
select 1 from table_fruit t2
where t2.account_id = t1.account_id
and t2.fruit <> 'apple'
);
试试这个:
Select * From table_fruit Where fruit = 'apple'
或选择*From table_fruit Where fruit like'%apple%'