0

在以下 mysql 查询中,我试图选择所有具有括号中所有功能的产品。我使用的 IN 显然返回具有功能 1 或功能 2 等的产品...我应该使用什么来代替 IN?

SELECT *, f.name as feature, p.productcode as productcode, p.name as name 
from product p 
left join productfeatures pf on p.productcode = pf.productcode 
left join features f on pf.featureid = f.id
where f.id in (1, 2, 3) 
group by p.productcode
4

1 回答 1

4

将此添加到末尾

having count(f.id) = 3

这只会导致具有 3 f.ids 而不仅仅是 1 或 2 的组。

如果您的子句f.id中有超过 3 个 s in,则需要扩展该值。例子:

where f.id in (1, 2, 3, 4, 5) 
group by p.productcode    
having count(f.id) = 5
于 2012-05-10T08:07:47.037 回答