gpt4 book ai didi

mysql - 选择同时喜欢苹果和香蕉的人

转载 作者:可可西里 更新时间:2023-11-01 06:37:32 24 4
gpt4 key购买 nike

如何从下面的数据中选出像苹果和香蕉一样的人?

表:我的表

persons |  fruit
-----------------------------
P1 Apple
P1 Banana
P1 Mango
P2 Banana
P2 Apple
P3 Mango
P3 Apple

即在这种情况下,P1、P2 应该是结果。

我试过

select * from MyTable where fruit in("Apple","Banana");

这也是 P3 的结果,因为 P3 也有苹果。

感谢您的帮助。

最佳答案

SELECT a.persons 
FROM MyTable a JOIN MyTable b on a.persons=b.persons
WHERE a.fruit='Apple' and b.fruit='Banana'

关于mysql - 选择同时喜欢苹果和香蕉的人,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27616677/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com