Filtering with WHERE · 用 WHERE 筛选
Filtering rows with WHERE
So far every query returned all the rows. Add a WHERE clause to keep only the rows that match a condition:
Only rows where the condition is true are returned.
用 WHERE 筛选行
到目前为止,每条查询都返回所有行。加上 WHERE 子句,只保留满足条件的行:
SELECT name, score FROM student WHERE score >= 80;
只有条件为真的行才会返回。
Comparison operators
You can compare with:
=equal to<>not equal to<less than,>greater than<=at most,>=at least
Numbers are written plainly (80). Text must go in single quotes ('11B'):
比较运算符
你可以这样比较:
=等于<>不等于<小于,>大于<=不大于,>=不小于
数字直接写(80)。文本必须放在单引号里('11B'):
SELECT name FROM student WHERE form = '11B';
Common mistakes
- Text values go in single quotes:
WHERE name = 'Ann'. WHEREcomes afterFROM.
常见错误
- 文本值用单引号:
WHERE name = 'Ann'。 WHERE写在FROM之后。
WHERE filters rows · WHERE 过滤行
WHERE keeps only the rows whose condition is true. · WHERE 只保留条件为真的行。
Show the name and score of every student who scored 80 or more. · 显示分数在 80 或以上的每名学生的 name 和 score。
Click Run to see the output here. · 点击“运行”查看此处输出。
Show the name of every student in form 11B. (Text goes in single quotes.) · 显示 11B 班每名学生的 name。(文本要放在单引号里。)
Click Run to see the output here. · 点击“运行”查看此处输出。