在SQL中实现foreach逻辑



我有一个Fruit表,如下所示:

红色
名称 属性
苹果 价格 5美元
苹果 颜色
苹果 数量 20
价格 $5
颜色 Kelly
重量 50g
质量 Good

您可以使用not exists:

select f.*
from fruit f
where f.name = 'Pear' and
not exists (select 1
from fruit f2
where f2.name = 'Apple' and
f2.property = f.property and
f2.value = f.value
);

最新更新