# SQL field guide

Three independent, fictional examples. No accounts, credentials, remote queries,
or production database are needed. Tested with DuckDB CLI 1.2.1.

1. Install the DuckDB command-line client for your operating system:
   https://duckdb.org/docs/installation/
2. Extract https://synehq.com/learn/sql-field-guide.zip. It contains this README,
   three SQL scripts, and orders.csv inside the synehq-sql-field-guide folder.
3. Open a terminal in that extracted folder. Run each lesson in a fresh
   in-memory session. In a macOS or Linux shell:

```sh
duckdb < csv-audit.sql
duckdb < join-fanout.sql
duckdb < cohort-retention.sql
```

On Windows, open the DuckDB CLI from the extracted folder and enter
`.read csv-audit.sql`. Enter `.quit` to close the session, then reopen DuckDB
for `.read join-fanout.sql` and again for `.read cohort-retention.sql`.

Individual files are also available from https://synehq.com/learn/.
Keep orders.csv beside csv-audit.sql when downloading them separately.

CSV audit: 6 source rows, 5 distinct order IDs, 1 invalid date, 1 invalid amount,
1 missing customer; order 002 occurs twice. Exception rows: 003, 004, 005.

Join fanout: the deliberately incorrect query returns 5 joined rows, 560.00
order total, and 50.00 refunds. The corrected query returns 2 orders, 200.00
order total, 35.00 refunds, and 165.00 net after refunds. The final uniqueness
check returns no rows.

Retention: January has 100%, 50%, 50% for months 0, 1, 2; February has 100%, 0%
for months 0, 1; March has 100% for month 0. Later, unobserved cells are absent.

These are teaching fixtures, not benchmarks or accounting policy. See
https://synehq.com/learn/ for definitions, limitations, and the full walkthroughs.
