Choosing columns · 选择列
Picking columns
SELECT * returns every column. Usually you want only a few. Instead of *, list the columns you want, separated by commas:
The result has just those columns, in the order you wrote them.
选择列
SELECT * 返回每一列。通常你只想要其中几列。不用 *,而是列出你想要的列,用逗号隔开:
SELECT name, score FROM student;
结果就只有这些列,顺序和你写的一样。
Renaming a column with AS
You can rename a column in the result with AS. This does not change the table — only the heading shown:
The headings become pupil and mark. This is handy for clear reports.
用 AS 给列改名
你可以用 AS 给结果中的列改名。这不会改动表本身 —— 只改变显示的标题:
SELECT name AS pupil, score AS mark FROM student;
标题就变成了 pupil 和 mark。这对做清晰的报表很有用。
Common mistakes
- List the columns you want, separated by commas.
ASrenames a column in the result.
常见错误
- 列出想要的列,用逗号分隔。
AS在结果中给列改名。
SELECT picks columns · SELECT 挑选列
Choosing columns keeps only the fields you name. · 选择列时只保留你点名的字段。
Select only the name and score columns from student, in that order. · 只从 student 选择 name 和 score 两列,按此顺序。
Click Run to see the output here. · 点击“运行”查看此处输出。
Select name and score, but rename the headings to pupil and mark using AS. · 选择 name 和 score,但用 AS 把标题改成 pupil 和 mark。
Click Run to see the output here. · 点击“运行”查看此处输出。