我有基本的 SQL 技能,但我对此感到困惑:
create table scores
(
name varchar2(15),
history_grade varchar2(1),
math_grade varchar2(1)
);
insert into scores (name, history_grade, math_grade) values ('Bill', 'A', 'A');
insert into scores (name, history_grade, math_grade) values ('Sue', 'F', 'F');
insert into scores (name, history_grade, math_grade) values ('Mary', 'C', 'B');
insert into scores (name, history_grade, math_grade) values ('Austin', 'C', 'A');
insert into scores (name, history_grade, math_grade) values ('Kyle', 'B', 'B');
我想查询
history_grade
和 math_grade
都不是“A”或都不是“F”的行。如果history_grade或math_grade中有一个是“A”或“F”,但另一个不是“A”或“F”,那么我仍然想要该行。
我正在尝试这个:
select *
from scores
where (history_grade <> 'A' and math_grade <> 'A')
and (history_grade <> 'F' and math_grade <> 'F' )
但这只会返回玛丽和凯尔。我需要结果集中有 Mary、Kyle 和 Austin,因为 Austin 只有一个 A,而不是两个 A。
我希望这是有道理的,非常感谢任何帮助!
select * from scores where
CONCAT( history_grade, math_grade ) not in('AA','FF')
NOT IN
:
SELECT *
FROM scores
WHERE (history_grade, math_grade) NOT IN (('A', 'A'), ('F', 'F'))