我有一个名为team
的表我需要选择一名也可能是球队球员的教练......
表的属性是 (teamID,playerID,角色)
我可以选择所有教练或所有球员,但不知道如何选择一个......
select *
from isPlaying h
where h.role= 'Coach';
由于
答案 0 :(得分:1)
select playerID
from isPlaying coach join isPlaying player on
coach.playerID = player.playerID
where
coach.role = 'Coach' and
player.role = 'Player'
答案 1 :(得分:0)
Select *
from isplaying
where playerid in (
Select playerid
from playerid
where role="coach"
);
这是一个嵌套查询。
答案 2 :(得分:0)
快速而肮脏的方法是:
select *
from isPlaying h
where h.role = 'Player'
and h.playerID in
(select playerID from isPlaying where h.role = 'Coach')
这是假设一名教练不能为一支不同于他教练的球队效力。
答案 3 :(得分:0)
SELECT playerID
FROM isPlaying
WHERE role = 'Coach'
INTERSECT
SELECT playerID
FROM isPlaying
WHERE role = 'Player';