Applied edition · 44 planned hours · Unpiloted · Human review pending. Self-review is not a credential; the full 108-hour semester remains unfinished. No browser SQL execution.

Download Markdown

Unit 3 — Unknown is not zero; suspicious is not disproved

Outcome U3: distinguish missing, zero and invalid values; expose duplicate identities and raw-record problems without silently repairing the source. Suggested work: five hours, including a quality log and independent task; unpiloted.

1. Three states that should not collapse

Booking 1002 has attended=0: attendance was recorded and none of its booked seats attended. Booking 1003 has attended=NULL: no attendance value is supplied. Session 106 has no booking rows at all. These are not interchangeable observations.

NULL is a marker of absent information, not a special number or empty text. It can mean different things in different datasets. Our dictionary says only “attendance count not recorded in the supplied fixture.” Do not infer refusal, absence, deletion or late arrival.

A comparison with NULL generally produces unknown rather than true or false. A WHERE clause keeps true results; unknown results do not pass. Consequently WHERE attended=0 selects the two base zero-attendance bookings, but it does not select the missing ones. WHERE attended<>0 also excludes missing ones. Those two filters do not partition all ten rows.

Use IS NULL and IS NOT NULL:

SELECT reg_id,session_id,seats FROM registrations
WHERE attended IS NULL ORDER BY reg_id;

The base result is (1003,101,1) and (1007,103,2): two records representing three booked seats. WHERE attended=NULL does not answer this question. There is no ordinary value on the right to compare with.

2. Audit the denominator alongside the total

COUNT(*) counts result rows. COUNT(attended) counts non-NULL attendance values. On base they produce 10 and 8. SUM(attended) ignores NULL inputs and adds the eight recorded values to 8. That sum is a count of recorded attended seats, not necessarily the final attendance total.

The record coverage is 8/10 = 80%. But the seat coverage is 11/14 ≈ 78.57%, because missing bookings reserve three seats. Coverage depends on what is being counted. Do not use a record-coverage percentage as a seat-coverage denominator.

COALESCE(attended,0) replaces missing values in an expression with zero. It does not repair the evidence. It is appropriate only when zero is a justified presentation or modeling convention and the missingness remains visible. In Unit 7 we use zero for an additive lower-bound component while separately displaying unknown seats. We never claim that missing attendance was observed to be zero.

Missingness states

Complete text alternative: three separate boxes: “Recorded zero: booking 1002, one booked seat, attendance 0”; “Unknown: booking 1003, one booked seat, attendance NULL”; “No booking row: session 106, capacity 3.” The first is an observed count, the second lacks a count, the third has no entity in the child table. No arrow equates them.

3. A staging table is an evidence queue

The raw intake table contains six rows. Ingest IDs 1 and 2 both claim registration 9001 with identical attributes. Ingest 3 points to session 999, which is absent. Ingest 4 lacks a registration ID. Ingest 5 requests zero seats. Ingest 6 records attendance 2 for a one-seat booking. They are deliberately problematic learning records, not additions to the trusted counts.

A duplicate-identity query groups by the proposed identity:

SELECT reg_id,COUNT(*) AS intake_rows FROM intake
WHERE reg_id IS NOT NULL
GROUP BY reg_id HAVING COUNT(*)>1 ORDER BY reg_id;

You will learn GROUP BY systematically next unit; here read its purpose: put claims with the same nonmissing identity together, count them, then keep groups with more than one claim. The result is (9001,2). That does not tell you which source message is authoritative or whether a retransmission should be retained in an audit history.

Do not use SELECT DISTINCT fee_cents as a duplicate-record detector. Many legitimate bookings share a price. Conversely two conflicting rows can claim the same ID while differing in seats; exact-row DISTINCT would not resolve that conflict. An identity rule and provenance are needed.

The supplied u03_invalid_intake query flags missing IDs, missing seat counts and impossible seat/attendance counts. It returns ingest IDs 4,5,6. It does not find the orphan session or duplicate identities; those are separate checks. A green check means a particular rule passed, not that the entire table is correct.

4. Constraints are guardrails, not truth machines

The trusted registration schema rejects duplicate primary keys, missing parent sessions, nonpositive seats, attendance above seats and negative fees. The local tests execute each rejection in a fresh in-memory database. They also verify that missing attendance is permitted, because unknown is a valid state in this case.

SQLite can generate an INTEGER PRIMARY KEY when an insertion supplies NULL. That is not an authoritative correction of a missing source identity. The intake check must flag a missing reg_id before admission; our supplied trusted fixtures always state their IDs explicitly.

A foreign key checks the existence of an identifier, not the truth of the association. Booking 1001 could be mistakenly linked to existing session 102 and still satisfy the relationship constraint. Similarly, a believable but wrong attendance count can pass a numeric check. Validation combines structural rules, source comparison and domain reasoning.

For a quality log, record source row, rule, evidence, effect, provisional handling, and resolution owner. Example: “Ingest 3 refers to session 999; no such session is in this fixture; exclude it from trusted analysis pending source clarification; retain the raw row.” Do not create session 999 with guessed attributes or delete the raw row. The workbook asks for a simulated correction request, not an actual message to anyone.

Practice and checkpoint

Complete G3 before I3. Preserve the initial missingness interpretation, run the relevant queries, then explain corrections. The independent raw intake uses different IDs but the same kinds of fault; count each class separately rather than add overlapping error counts into a supposedly unique total.

Checkpoint C3 asks whether replacing every NULL with zero makes the dataset more complete. A satisfactory answer distinguishes a changed representation from new evidence, and names a measure that would become misleading. Add a quality-log.md to the cumulative project. Keep raw rows separate from admitted rows throughout the course.