Skip to content

Choosing columns

Databases & SQL Lesson 2 1:26 English narration · English + 中文 subtitles burned in

space play · ←/→ 5s · j/l 10s · f fullscreen · ,/. speed

Chapters

Transcript
A star gives you every column, and usually you want only a few. 星号给你所有的列,而通常你只想要其中几列。
So instead of the star, list the ones you want, separated by commas. 所以不用星号,改成把你要的列名列出来,用逗号分开。
The result keeps the two you named and drops the others. 结果保留你点名的那两列,把其余的丢掉。
And look carefully at what did NOT change: every row is still there. 再仔细看什么没有变:每一行都还在。
Naming columns cuts the table lengthways. 点名列,是把这张表竖着切。
The columns come back in the order you wrote them, not the order they sit in the table. 列是按你书写的顺序回来的,不是按它们在表里排列的顺序。
Swap the two names in the query and the two columns swap in the result. 在查询里把两个列名对调,结果里那两列也就对调了。
That is worth knowing when a question asks for a report with the columns in a particular order. 当题目要求报表按特定顺序排列各列时,这一点值得记住。
AS gives a column a different heading in the result. AS 给某一列在结果里换一个标题。
Here name is shown as pupil and score as mark, which reads better in a report. 这里 name 显示成 pupil,score 显示成 mark,在报表里读起来更顺。
One thing to be clear about: the stored table still has name and score. 有一点要弄清楚:存着的那张表里仍然是 name 和 score。
AS changes the heading you are shown, and nothing else — the data on disk has not moved. AS 只改变你看到的那个标题,别的什么都没改—— 磁盘上的数据一点没动。
Four things to take with you. 带走四点。
One: list the columns you want, separated by commas. 第一:把你要的列列出来,用逗号分开。
Two: they come back in the order you wrote them. 第二:它们按你书写的顺序回来。
Three: AS renames a column in the result. 第三:AS 在结果里给一列重命名。
Four: AS never changes the stored table. 第四:AS 从不改变存着的那张表。
Now run the tasks below. 现在去做下面的题。

Log in or create account

IGCSE, A-Level & AP