Oracle11g
我想知道一个球员是否曾经玩过游击手。但是,一个玩家甚至可能不在我的桌子上,但我仍然想为该玩家返回一行。在这种情况下,玩家 #3 不在桌子上,但我还是想返回一行。
选择标准
如果玩家至少有一个 SHORTSTOP 记录,则只返回 1 行 YES。
如果玩家至少有一个记录并且没有一个是 SHORTSTOP,那么只返回一行 NO。
如果玩家没有记录,则只返回一行 NO。
询问
with baseball_players as
(select 1 as player_id, 'SHORTSTOP' as position from dual union all
select 1 as player_id, 'FIRSTBASE' as position from dual union all
select 2 as player_id, 'FIRSTBASE' as position from dual)
select player_id, case position
when 'SHORTSTOP' then 'YES'
else 'NO'
end has_played
from baseball_players
where player_id in (1,2,3)
问题:如何编写查询以获得所需的结果?
期望的输出
PLAYER_ID HAS_PLAYED
----------------------
1 YES
2 NO
3 NO