Open lesson

Mission: three rows, how many facts?

Command palette

This mission workspace keeps code and notes in this browser tab. Export them before closing it. Running code is practice, not an automatic grade for the mission.

Brief

Calculate SQL totals by group and explain exactly what each number counts, especially when a value is missing.

In the story, Imani receives Voss’s slide: “three Noctis, therefore three proofs.” Mara puts down six fictional checks: C1 Noctis North 4, C2 Noctis South 6, C3 Noctis South NULL, C4 Test-02 South 3, C5 Test-02 North 5, C6 Test-03 North 2. Voss is due to present his claim in a few fictional minutes; prepare an explanation a new juror can understand.

Your mission

  1. Give COUNT(*), COUNT(duration_min), SUM(duration_min) and AVG(duration_min) for Noctis.
  2. Give the same four numbers for Test-02 and count its distinct gates.
  3. Write a query displaying only codes with at least two rows.
  4. Explain why “three Noctis rows” means neither “three cars” nor “three independent proofs.”

How to check your work

  • Noctis has 3 rows, 2 known durations, total 10 and average 5.
  • Test-02 has 2 rows, 2 known durations, total 8, average 4 and 2 gates.
  • GROUP BY vehicle HAVING COUNT(*) >= 2 retains Noctis and Test-02.
  • Rows may repeat a code or share a source; independence and physical identity require checking.

Course example

SELECT vehicle,
       COUNT(*) AS rows_count,
       COUNT(duration_min) AS known_durations,
       SUM(duration_min) AS total_minutes,
       AVG(duration_min) AS average_minutes,
       COUNT(DISTINCT gate) AS gates
FROM checks
GROUP BY vehicle
HAVING COUNT(*) >= 2;

SQLite schema and synthetic input

CREATE TABLE checks (id TEXT PRIMARY KEY, vehicle TEXT, gate TEXT, duration_min INTEGER);
INSERT INTO checks VALUES ('C1', 'NOCTIS-01', 'North', 4), ('C2', 'NOCTIS-01', 'South', 6), ('C3', 'NOCTIS-01', 'South', NULL), ('C4', 'TEST-02', 'South', 3), ('C5', 'TEST-02', 'North', 5), ('C6', 'TEST-03', 'North', 2);

Code

Use Tab to leave the editor. Ctrl+Enter runs the source. The lines beginning with -- are task reminders. SQL ignores them. Write your query beneath them.

SQL console

Loading laboratory…

Explore Python or SQL here; this is not an operating-system shell.

This is a disposable browser experiment. The code run here is not recorded as a completed mission.

Each command starts a fresh disposable worker: it runs a captured copy of your current source, then your command with the lesson fixtures. Changes are discarded afterward. Commands never save source or award XP. Ctrl+Enter executes the command.

Virtual workspace files

Source and declarative assets are readable here without JavaScript. Python input files are created at runtime; SQL setup initializes the disposable database.

source.sql

Current editor source. Inspection shows your current edits.

-- Give `COUNT(*)`, `COUNT(duration_min)`, `SUM(duration_min)` and `AVG(duration_min)` for Noctis.
-- Give the same four numbers for Test-02 and count its distinct gates.
-- Write a query displaying only codes with at least two rows.
-- Explain why “three Noctis rows” means neither “three cars” nor “three independent proofs.”

exemple.sql

Declarative lesson asset; this is not a file created in the Python filesystem.

SELECT vehicle,
       COUNT(*) AS rows_count,
       COUNT(duration_min) AS known_durations,
       SUM(duration_min) AS total_minutes,
       AVG(duration_min) AS average_minutes,
       COUNT(DISTINCT gate) AS gates
FROM checks
GROUP BY vehicle
HAVING COUNT(*) >= 2;
donnees.sql

Declarative lesson asset; this is not a file created in the Python filesystem.

CREATE TABLE checks (id TEXT PRIMARY KEY, vehicle TEXT, gate TEXT, duration_min INTEGER);
INSERT INTO checks VALUES ('C1', 'NOCTIS-01', 'North', 4), ('C2', 'NOCTIS-01', 'South', 6), ('C3', 'NOCTIS-01', 'South', NULL), ('C4', 'TEST-02', 'South', 3), ('C5', 'TEST-02', 'North', 5), ('C6', 'TEST-03', 'North', 2);