【发布时间】:2015-04-10 21:26:12
【问题描述】:
我正在尝试获取以下示例的查询,其中我需要选择与某个人为同一支球队(或同一支球队和其他球队)效力的所有人。例如
person teamName
1 maple leafs
1 rangers
2 red wings
3 rangers
3 avalanche
3 maple leafs
我正在尝试创建一个查询,显示“查找与球员 1 曾在同一支球队效力的所有球员”。在上面的示例中,它应该返回玩家 1 和 3。我有一些工作,即
select person from teams where teamName = 'maple leafs' intersect select person from teams where teamName = 'rangers';
但是编码太难了(玩家可能会被派往另一支球队)。我可以通过以下方式获取已加入玩家 1 团队的玩家列表
create table temp as select teamName from teams where person = 1;
select * from temp join teams on temp.teamName = teams.teamName;
但是我不知道如何提取与玩家 1 在所有相同团队中的人。我尝试过 group by 并设置子句,但是当我按人分组时,除第一个以外的任何团队都会丢失,所以我有点卡住了。
感谢任何帮助。
【问题讨论】:
标签: sql sqlite multivalue