Databases & SQL · 数据库与 SQL
This page needs a recent browser (with SharedArrayBuffer support). Please update Chrome, Edge, Firefox or Safari to the latest version. · 此页面需较新浏览器(支持 SharedArrayBuffer)。请升级 Chrome、Edge、Firefox 或 Safari 至最新版本。
English
A database stores tables
- A database keeps data in tables, like a spreadsheet.
- Each row is a record; each column is a field.
- We ask questions in a language called SQL.
中文
数据库存放数据表
- 数据库(database)把数据存放在表(table)里,就像电子表格。
- 每一行是一条记录(record);每一列是一个字段(field)。
- 我们用一种叫 SQL 的语言来提问。
English
SELECT: choose columns
SELECTpicks which columns to show.FROMnames the table to read.*means "all columns".
中文
SELECT:选择列
SELECT挑选要显示哪些列。FROM指定要读取的表。*表示“所有列”。
SELECT name, grade FROM student;
English
WHERE: filter rows
WHEREkeeps only the rows whose condition is true.- Put text in single quotes:
'A'.
中文
WHERE:筛选行
WHERE只保留条件为真的行。- 文本放在单引号里:
'A'。
Explore · 探索
SELECT … WHERE, visualized · SELECT … WHERE 可视化
WHERE keeps only matching rows; SELECT then keeps only the chosen columns. · WHERE 只保留匹配的行;SELECT 再只保留选中的列。
SELECT name FROM student WHERE grade = 'A';
English
ORDER BY: sort the results
ORDER BYsorts the rows by a column.- Add
DESCfor largest first, orASC(the default) for smallest first.
中文
ORDER BY:给结果排序
ORDER BY按某一列给行排序。- 加
DESC表示从大到小,ASC(默认)表示从小到大。
SELECT name, age FROM student ORDER BY age DESC;
English
In the exam: SQL
- IGCSE uses exactly these clauses:
SELECT … FROM … WHERE … ORDER BY.
中文
在考试里:SQL
- IGCSE 只用这几个子句:
SELECT … FROM … WHERE … ORDER BY。
SELECT Name, Grade
FROM Student
WHERE Grade = 'A';
English
Common mistakes
- Text values go in single quotes:
WHERE name = 'Ann'. SELECTchooses the columns;WHEREfilters the rows.
中文
常见错误
- 文本值用单引号:
WHERE name = 'Ann'。 SELECT选择列;WHERE筛选行。
English
Now you try
- Write one SQL query for each task.
- Press Check answer to run it against the table.
中文
现在轮到你
- 为每个任务写一条 SQL 查询。
- 按检查答案,在这张表上运行它。
Show the name of every student. (Use SELECT name FROM student;.) · 显示每名学生的 name。(用 SELECT name FROM student;。)
Click Run to see the output here. · 点击“运行”查看此处输出。
Show the name and grade of every student whose grade is A. (Text goes in single quotes: 'A'.) · 显示 grade 为 A 的每名学生的 name 和 grade。(文本放在单引号里:'A'。)
Click Run to see the output here. · 点击“运行”查看此处输出。
Show the name of every student, oldest first (sort by age in descending order). · 显示每名学生的 name,最年长的在前(按 age 降序排序)。
Click Run to see the output here. · 点击“运行”查看此处输出。