AND, OR, NOT · AND、OR、NOT
Combining conditions
A WHERE clause can test more than one thing at once. Join conditions with:
AND— both must be trueOR— at least one must be trueNOT— flips a condition
This returns 11A students who also scored above 88.
组合条件
一个 WHERE 子句可以同时测试不止一件事。用下面的词连接条件:
AND—— 两个都必须为真OR—— 至少一个为真NOT—— 把条件反过来
SELECT name FROM student WHERE form = '11A' AND score > 88;
这会返回那些 11A 班、并且分数高于 88 的学生。
Mixing AND and OR
When you mix AND and OR, use brackets to make the meaning clear, just like in maths:
AND is checked before OR, so brackets remove any doubt about what you mean.
混用 AND 和 OR
当你混用 AND 和 OR 时,用括号把意思写清楚,就像在数学里一样:
SELECT name FROM student
WHERE form = '11B' OR score >= 95;
AND 会先于 OR 判断,所以括号能消除歧义。
Common mistakes
- Use brackets when you mix
ANDandORto make the order clear. NOTreverses a condition.
常见错误
- 混用
AND和OR时用括号,让顺序清楚。 NOT把条件反过来。
AND, OR, NOT · AND、OR、NOT
Combine conditions with AND/OR/NOT — see the truth table. · 用 AND/OR/NOT 组合条件——看真值表。
Show the name of every student who is in form 11A and scored more than 88. · 显示既在 11A 班、并且分数高于 88 的每名学生的 name。
Click Run to see the output here. · 点击“运行”查看此处输出。
Show the name of every student who is in form 11B or · 或 scored 95 or more. · 显示在 11B 班、或者分数在 95 或以上的每名学生的 name。
Click Run to see the output here. · 点击“运行”查看此处输出。