Level 6 / Project 07 - SQL Summary Publisher¶
Home: README
Learn Your Way¶
| Read | Build | Watch | Test | Review | Visualize | Try |
|---|---|---|---|---|---|---|
| — | This project | — | — | Flashcards | — | — |
Focus¶
- daily aggregate publication flow
Why this project exists¶
This project gives you level-appropriate practice in a realistic operations context. Goal: run the baseline, alter behavior, break one assumption, recover safely, and explain the fix.
Run (copy/paste)¶
Use <repo-root> as the folder containing this repository's README.md.
cd <repo-root>/projects/level-6/07-sql-summary-publisher
python project.py --input data/sample_input.txt --output data/output_summary.json
pytest -q
Expected terminal output¶
{
"total_sales": 7,
"total_revenue": 1374.10,
"by_region": [...],
"by_product": [...],
"top_sale": {"product": "Widget", "region": "West", "revenue": 299.70}
}
Expected artifacts¶
data/output_summary.json— aggregate metrics as JSONdata/output_summary.txt— human-readable formatted report- Passing tests (
pytest -q→ 6+ passed) - Updated
notes.md
Alter it (required)¶
- Add a "bottom performer" section showing the product with the lowest total revenue.
- Add a
--min-revenuefilter that excludes sales below a threshold from the summary. - Add a date-range filter:
--fromand--toflags to limit which sales are included. - Re-run script and tests after each change.
Break it (required)¶
- Feed an empty sales array
[]and observe how the aggregates handle zero rows. - Include a sale with a negative revenue value and observe the summary.
- Feed sales with a region name containing special characters.
Fix it (required)¶
- Add a guard for empty datasets that returns zeroed-out metrics instead of errors.
- Validate that revenue is non-negative before including in aggregates.
- Add tests for edge cases.
Explain it (teach-back)¶
- What is the difference between
SUM,COUNT,AVG,MIN, andMAXin SQL? - Why do we use
COALESCEwith aggregate functions? - What happens if GROUP BY produces zero groups?
- When would you use a subquery vs a simple GROUP BY?
Mastery check¶
You can move on when you can: - run baseline without docs, - explain one core function line-by-line, - break and recover in one session, - keep tests passing after your change.
Related Concepts¶
| ← Prev | Home | Next → |
|---|---|---|