# SQL Reporting Lab

By Chason Arthur
Revision 127.036
Published/updated 2026-11-04

## Start without installing dependencies

Extract this complete ZIP into a new folder. With Python 3 installed, run `python preview.py` from the extracted root. Open http://127.0.0.1:4210/. Stop with Ctrl+C. The prebuilt site is self-contained and makes no automatic external requests. Written reference links are optional. Do not open the files directly with file:// because workers and Wasm need HTTP.

## Run the native exercise

```sh
npm ci
npm test
npm run rebuild
python preview.py
```

The native Node tests execute PostgreSQL queries through PGlite, including exact revenue and time-zone assertions. PGlite is an embedded single-client database. Use a separate PostgreSQL deployment and realistic data before making concurrency or performance claims.

## Expected result

Revenue is 42000 cents with the multiplying join and 30000 at order grain. The local-day example returns 26000 cents; the UTC-day query returns 24000. The safeguarded cohort has one A user and two B users.

## Scope

Actual PostgreSQL runs through the open-source PGlite runtime in a fresh in-memory worker. Four invented orders explain correctness. Their query plans do not establish warehouse cost, index benefits or production performance.

## Change and rebuild

Node/browser packages: `npm ci`, `npm run rebuild`, then `python preview.py`. Go: edit src/go, run its tests and `python rebuild_wasm.py` before refreshing source. Python: edit src/python/engine.py and run `python refresh_source.py`. Rebuild keeps the local preview and source viewer aligned. FILE_MANIFEST.json describes the initial extracted package, not later edits. The source-map and source viewer manifest record the exact teaching files. Update edition/date metadata before publishing an edited version.

## Extension

Add two distinct orders with the same amount and demonstrate why SUM(DISTINCT amount_cents) is an invalid fanout repair. Then define a late-arrival cutoff and keep that policy fixed while comparing implementations.

Original teaching code and lessons are MIT-licensed. See THIRD_PARTY_NOTICES.md and licenses/. The package starts no production API, model, payment, email or cloud service.
