我有一个这样的表:
Tb_Product_Options
:
Product_Id Option_Id
1 5
1 7
2 3
3 9
3 6
现在我想让所有Product_Id
的人都没有这个值:'5,9'
。在这个例子中我的结果必然是:2
(product_id
)
您可以聚合:
select Product_Id
from table t
group by Product_Id
having sum ( Option_Id in (5,9) ) = 0;
如果需要所有列,则可以使用NOT EXISTS
:
select t.*
from table t
where not exists (select 1
from table t1
where t1.Product_Id = t.Product_Id and t1.Option_Id in (5,9)
);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句