[我知道我的问题很奇怪,但我不知道如果我想查看所有从未失去战斗的拳击手的姓氏,那么select应该在oracle中显示如何。
所以我有:
我如何选择永远不会在甲骨文打架的拳击手?我有oracle 11g Express Edition。 (不,我无法更新,我的教授说我的答案应该在11g上工作)。
对不起,如果我的问题不符合此页面的条件。
我尝试了一些东西,但我不知道如何选择那些永不丢失的东西:
select b1.lname, b2.lname
from boxer b1
join fight f
on b1.id_boxer=w.id_boxer1
join boxer b2
on b2.id_boxer=w.id_boxer2
where f.winner= ...;
您可以使用不存在:
select b.*
from boxer b
where not exists (select 1 from fight f where f.id_boxer_2 = b.id)
[如果您想至少战斗一次的拳击手并且永不丢失:
select b.*
from boxer b
where
exists (select 1 from fight f where f.id_boxer_1 = b.id)
and not exists (select 1 from fight f where f.id_boxer_2 = b.id)
我将使用case
表达式从fight
表中获取失败的拳击手,然后使用boxer
运算符查询not exists
表:
SELECT *
FROM boxer b
WHERE NOT EXIST (SELECT *
FROM fight
WHERE b.id = CASE winner WHEN 1 THEN id_boxer2 ELSE id_boxer1 END)