我有一个联盟中的玩家模式,看起来像架构打击。来自架构的SQL行查询
Player (playerid integer, mentorid integer, leagueid integer, pay integer)
League (leagueid integer, leaguename text)
我想找到那些不指导任何人的球员。那会是什么问题?
(所以我基本上希望找到playerid
列中不存在在mentorid
列中的条目)
我有一个联盟中的玩家模式,看起来像架构打击。来自架构的SQL行查询
Player (playerid integer, mentorid integer, leagueid integer, pay integer)
League (leagueid integer, leaguename text)
我想找到那些不指导任何人的球员。那会是什么问题?
(所以我基本上希望找到playerid
列中不存在在mentorid
列中的条目)
select *
from player
where playerid not in (select distinct mentorid from player)
子选择中的'distinct'对于'IN'或'NOT IN'条件是无用的。 –
被这里的模式去。 SQL查询应该很容易:
SELECT * FROM Player WHERE mentorid is NULL
这只会令自己不要有mentorid即谁不指导任何人谁球员的条目。
备选: SELECT a.playerid FROM Players a RIGHT JOIN Players b ON a.playerid = b.mentorid WHERE a.playerid IS NOT NULL
Downvoter请说明理由? – Programmer345
此问题没有显示任何研究工作。 –