Filtering with WHERE
Databases & SQL Lesson 3 1:58 English narration · English + 中文 subtitles burned in
Chapters
Transcript
Every query so far returned all the rows.
到目前为止每一条查询都返回了所有的行。
WHERE changes that: it keeps only the rows that match a condition.
WHERE 改变了这一点:它只保留满足条件的那些行。
Scores of eighty or more, and the other two students fade out.
分数在 80 或以上,另外两个学生就淡出了。
Now look at what did NOT change: every column is still there.
现在看什么没有变:每一列都还在。
Where naming columns cut the table lengthways, WHERE cuts it across.
点名列是把表竖着切,而 WHERE 是把它横着切。
Here they are together, on one table, and this is the picture to keep.
这里是它们放在一起、在同一张表上的样子,而这就是要记住的那张图。
SELECT name and score keeps two columns.
SELECT name, score 保留了两列。
WHERE score at least eighty keeps three rows.
WHERE score >= 80 保留了三行。
They are cutting at right angles to each other, and what survives both cuts is the result.
它们是互相垂直地在切, 而同时挺过这两刀的部分,就是结果。
Any time you are unsure which clause to use, ask whether you want fewer columns or fewer rows.
任何时候你拿不准该用哪个子句,就问自己: 我是想要更少的列,还是更少的行。
Six operators do the comparing, and five are what you would guess.
有六个运算符负责比较,其中五个就是你会猜到的。
The sixth is worth a note: in SQL, not-equal is written as a pair of angle brackets, less-than followed by greater-than — not the exclamation-mark version you use in Python.
第六个值得记一笔: 在 SQL 里,"不等于"写成一对尖括号,小于号后面跟大于号—— 不是你在 Python 里用的那个带感叹号的写法。
Some databases accept both; the exam wants the first.
有些数据库两种都接受;考卷要的是前一种。
One rule about values, and it is the error you will hit first.
关于"值"有一条规则,而它是你最先会撞上的那个错误。
Text must go in single quotes — form equals eleven B, in quotes.
文字必须放在单引号里——form = '11B',带引号。
Numbers are written plainly, with no quotes at all.
数字光着写,完全不加引号。
Quote a number and some databases will still compare it as text, which sorts one hundred before ninety.
给数字加了引号,有些数据库仍然会按文字去比较, 那样 100 会排在 90 前面。
Four things to take with you.
带走四点。
One: WHERE keeps only the rows whose condition is true.
第一:WHERE 只保留条件为真的那些行。
Two: SELECT cuts columns and WHERE cuts rows.
第二:SELECT 切列,WHERE 切行。
Three: text goes in single quotes and numbers do not.
第三:文字加单引号,数字不加。
Four: WHERE comes after FROM.
第四:WHERE 写在 FROM 之后。
Now run the tasks below.
现在去做下面的题。