Databases & SQL
このページには最新のブラウザ(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.

English
SELECT: choose columns
SELECTpicks which columns to show.FROMnames the table to read.*means "all columns".
English
SELECT name, grade FROM student;
English
WHERE: filter rows
WHEREkeeps only the rows whose condition is true.- Put text in single quotes:
'A'.
探索
SELECT … WHERE, visualized
WHERE keeps only matching rows; SELECT then keeps only the chosen columns.
English
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.
English
SELECT name, age FROM student ORDER BY age DESC;
English
AND and OR: two conditions
ANDkeeps a row only when both conditions are true.ORkeeps a row when at least one is true.
English
SELECT name, age FROM student WHERE grade = 'A' AND age >= 17;
English
COUNT and SUM
COUNT(*)counts the rows that match;SUM(field)adds up a number field.- Name the answer with
AS, so its column has a clear heading.
English
SELECT COUNT(*) AS n FROM student WHERE grade = 'A';
English
In the exam: SQL
- IGCSE uses
SELECT,FROM,WHERE,ORDER BY,SUMandCOUNT, withAND,ORand the comparisons=,<>,<,>,<=,>=. - The primary key is a field whose value is different in every record, like
idhere. - To work out what a query shows, read it as FROM → WHERE → SELECT → 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.- Show only the fields the question asks for: filtering on
gradedoes not meangradebelongs inSELECT. - "How many" is
COUNT; "total" isSUM.
English
Now you try
- Write one SQL query for each task.
- Press Check answer to run it against the table.
難易度 3/5 · 200 コイン + 今日初回達成時の小ボーナス
Show the name of every student. (Use SELECT name FROM student;.)
実行ボタンをクリックして出力を確認してください。
難易度 3/5 · 200 コイン + 今日初回達成時の小ボーナス
Show the name かつ grade of every student whose grade is A. (Text goes in single quotes: 'A'.)
実行ボタンをクリックして出力を確認してください。
難易度 3/5 · 200 コイン + 今日初回達成時の小ボーナス
Show the name of every student, oldest first (sort by age in descending order).
実行ボタンをクリックして出力を確認してください。
難易度 3/5 · 200 コイン + 今日初回達成時の小ボーナス
Show the name of every student whose grade is A かつ whose age is under 17. Show only the name field.
実行ボタンをクリックして出力を確認してください。
難易度 3/5 · 200 コイン + 今日初回達成時の小ボーナス
In one query, show how many students there are as n。また、次の規約が適用されます: 総数 of their merits as total.
実行ボタンをクリックして出力を確認してください。