我有一個叫團隊SQL查詢幫助加入
,我需要選擇誰也可能是對球隊球員教練表....
該表的屬性 (teamID, playerID,角色)
我能夠選擇所有教練和所有球員,但不知道如何選擇一個這既是.....
select *
from isPlaying h
where h.role= 'Coach';
感謝
我有一個叫團隊SQL查詢幫助加入
,我需要選擇誰也可能是對球隊球員教練表....
該表的屬性 (teamID, playerID,角色)
我能夠選擇所有教練和所有球員,但不知道如何選擇一個這既是.....
select *
from isPlaying h
where h.role= 'Coach';
感謝
select playerID
from isPlaying coach join isPlaying player on
coach.playerID = player.playerID
where
coach.role = 'Coach' and
player.role = 'Player'
Select *
from isplaying
where playerid in (
Select playerid
from playerid
where role="coach"
);
這是一個嵌套查詢。
的要求是 「還」,這樣就需要一個在where子句中是「OR」。你的建議只會選擇「有」教練的球員。 – 2011-06-01 12:27:40
一個快速和骯髒的方式做到這一點是:
select *
from isPlaying h
where h.role = 'Player'
and h.playerID in
(select playerID from isPlaying where h.role = 'Coach')
這是假設一個教練無法爲一支不同的球隊比他的教練進行播放。
SELECT playerID
FROM isPlaying
WHERE role = 'Coach'
INTERSECT
SELECT playerID
FROM isPlaying
WHERE role = 'Player';
在這種情況下,「可能」意味着什麼?僅有球員或教練是否有任何表格? – Bastardo 2011-06-01 12:30:33
團隊ID = TEAM1 玩家ID = P1 作用=玩家 團隊ID = TEAM1 玩家ID = P1 作用=教練 這應該給我這個playerID – user779214 2011-06-01 12:35:13