# Advanced analytical SQL / existing SQL Operations project

Data: existing /source/python-revenue-inventory CSVs and /assets/data/operations.json (36 sales, 6 SKUs, 6 months). Supplier mapping is synthetic: Tea → SUP-TEA, Coffee → SUP-COF, Tableware → SUP-POT.

Eight executable examples include JOIN, CTE, cumulative SUM, DENSE_RANK, category GROUP BY, CASE-based ABC, LAG/LEAD and quality checks. results.json and CSV files are actual SQLite outputs, not manually typed examples. These queries use a common SQL subset supported by PostgreSQL; no PostgreSQL-engine run is claimed. schema.sql is a demo schema, not a production migration.

Revenue and cost are amounts in RUB. No returns in this source. Gross profit excludes overhead, tax, commission and logistics. Supplier mapping does not describe real counterparties. ABC assigns the item crossing a threshold to the preceding class using cumulative revenue before that item; deterministic tie-breaker is SKU. LAG/LEAD refer to adjacent observed months; the fixture has all six months. In a sparse real dataset create a calendar spine first. Date validity is an ingestion responsibility, not validated by substr(). Quality checks flag duplicate candidates for review; identical business lines are not automatically deleted.

Reproduce from the KASKAD repository: python3 scripts/upgrade_sql.py (standard library only). The script builds an in-memory database, executes all queries, reconciles independent totals and checks a negative fixture. Existing SQL regression tests remain unchanged.
