我有一个包含列的表“product_attribute_option”
product_id attribute_id attribute_option_id
1 9 15
1 15 23
2 9 15
2 11 18
2 12 19
3 9 15
3 15 23
现在我想按 attribute_option 过滤产品。
如何获取attribute_option_id为15和23的不同product_id?
最佳答案
您可以使用聚合和 having
子句:
select product_id
from t
where attribute_option_id in (15, 23)
group by product_id
having count(distinct attribute_option_id) = 2;
关于mysql - 如何在 Laravel Eloquent 方法或 SQL 中选择具有相同列条件的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66990851/