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
- Give
COUNT(*),COUNT(duration_min),SUM(duration_min)andAVG(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.”
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(*) >= 2retains 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);