对不起,我不确定如何正确表达此问题。这是我正在谈论的示例:
# food type
1 muffin vegan
2 pasta vegan
3 cookie vegan
4 burger vegan
5 bread idk
6 boba idk
7 muffin ok
8 pasta ok
9 muffin no
10 pasta yes
11 muffin hi
所以我想返回所有包含相同类型的松饼和面食的行。因此,如果我的查询正确,则将返回:
1 muffin vegan
2 pasta vegan
3 cookie vegan
4 burger vegan
7 muffin ok
8 pasta ok
我该怎么做?
答案 0 :(得分:0)
select * from T where type in (
select type from T
where food in ('muffin', 'pasta')
group by type
having count(distinct food) = 2
);