假设我有一个 SQL 中的 table1,如下所示。
Team PlayerID
Team1 12
Team2 56
Team1 78
Team1 96
Team3 23
Team2 45
Team3 89
Team3 78
现在我有一个新的 table2 作为
PlayerID Gender
12 Male
56 Female
78 Female
96 Male
23 Female
45 Male
89 Female
78 Female
有没有办法列出所有只有女性的团队?
最佳答案
您可以使用join
、group by
和having
:
select t.team
from teams t join
players p
on p.playerid = t.playerid
group by t.team
having min(gender) = max(gender) and min(gender) = 'Female';
关于mysql - 如何从 SQL 中的表中进行选择,其中列中的元素仅包含另一列的一个特征,而另一列本身又包含两个特征?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54714750/