Computer Science • Databases

SQL Challenges

The database

Question

SQL Challenges — Explanation

You're connected to a database, and each question asks you to find something out by writing an SQL query. Your queries run on your own copy of the database, in your browser, so try anything: you can't break it.

Some questions show a query and ask what it outputs instead. Questions marked AS go beyond IGCSE: AVG, MIN, MAX, LIKE (with % standing for any characters) and GROUP BY.

Checking. Your query is run and its result is compared with the right answer's, so any query that gives the right rows is right, whatever its column names. When a question asks for an order, your rows must be in that order too. If it's not right, you're told what's different, and you can try again; Show the answer gives a query that works. Explore, in the title bar, lets you run any query on the database, unchecked.

Mysteries. A mystery is a case to solve with several tables of evidence: join them (INNER JOIN), count and add them up (GROUP BY, COUNT, SUM), and keep your own list of suspects, with CREATE TABLE, ALTER TABLE, INSERT INTO, UPDATE and DELETE FROM, as in Cambridge AS 9618. The evidence can't be changed, but your own tables can. Each step is checked against your database; everything you change is kept, so you can stop and carry on, or start the case again.

Signed in, your queries are saved: come back and carry on. A question counts once you've got it right without being shown the answer. Questions your teacher has set are marked, and come up first.

Objective: read, understand and complete SQL scripts to query data stored in a single database table (Cambridge IGCSE Computer Science 0478, 9.4), and write SQL to query data (9618 8.3).

SQL Challenges — Key Terms

Key concepts in English, with te reo Māori, Chinese (Simplified) and Korean.

EnglishTe reo Māori中文(简体)한국어What it means on this page
Databasepātengi raraunga数据库데이터베이스A structured collection of related tables: here, the one you are connected to.
Table (relation)ripanga表테이블A grid of rows and columns holding data about one kind of thing, such as songs.
Row (record)haupae / pūkete行행One entry in a table: here, one song.
Column (field)tīwae / āpure字段필드One named piece of data stored for every row, such as Title or Year.
Primary keypātuhi matua主键기본 키The field that identifies each row of a table, such as SongID.
SQL (Structured Query Language)no attested term结构化查询语言 (SQL)구조적 질의 언어 (SQL)The standard language for defining, querying and changing the data in a relational database.
Queryno attested term查询질의 (쿼리)A request for data from a database, written in SQL: SELECT the columns FROM a table WHERE a condition is true.
Conditionno attested term条件조건A test that is true or false for each row, after WHERE: only the rows where it is true are kept.
Ascending order (ASC)no attested term升序오름차순Smallest, earliest or A first: ORDER BY Year ASC.
Descending order (DESC)no attested term降序내림차순Largest, latest or Z first: ORDER BY Year DESC.
Aggregate functionno attested term聚合函数집계 함수A function that works out one value from many rows: COUNT counts them, SUM adds up a column.

On the te reo Māori column. Terms marked as gaps have no attested equivalent in the sources checked — Karaitiana Taiuru's Dictionary of Māori Computer and Social Media Terms, Paekupu, the Reserve Bank's te reo financial glossary, NZQA and Te Aka. No coinage is printed as though it were established; where a class needs one, commission it from Te Taura Whiri i te Reo Māori and credit the translator. Te reo Māori is not italicised and takes no plural "s".