Explainable business reporting · Original fictional data · Free files and full answers
Rank products by gross revenue that fail a margin floor
For period2, a SKU fails if (price-cost)*100<20*price before returns. Return sku,gross_revenue,margin_pct rounded2 for failures sorted revenue descending,sku.
Use this fixed business case to build a checked CSV and a replayable SQL handoff. No account required. Scenario datasets are shared across related exercises; each exercise has its own decision and output contract.
Your output contract
- For period2, a SKU fails if (price-cost)*100<20*price before returns. Return sku,gross_revenue,margin_pct rounded2 for failures sorted revenue descending,sku.
- Return exactly the declared columns and order. Money uses integer cents; time and date units follow the task and field dictionary. NULL is unknown and differs from numeric zero.
- These are original fictional records and exercise policies. Scenario data may be shared with related tasks, whose decisions and output contracts differ.
Return columns exactly as sku, gross_revenue, margin_pct. Sort order follows the task. Output has 1 rows; an empty CSV field means NULL.
Source data
sales
7 source rows · Download sales CSV
| id INTEGER | sku TEXT | channel TEXT | period INTEGER | qty INTEGER | price INTEGER | cost INTEGER | returned INTEGER |
|---|---|---|---|---|---|---|---|
| 1 | A | search | 1 | 10 | 100 | 60 | 1 |
| 2 | B | 1 | 5 | 200 | 150 | 0 | |
| 3 | C | social | 1 | 4 | 300 | 200 | 1 |
| 4 | A | search | 2 | 12 | 120 | 65 | 2 |
| 5 | B | 2 | 4 | 190 | 150 | 1 | |
| 6 | C | search | 2 | 6 | 280 | 210 | 0 |
| 7 | D | social | 2 | 3 | 500 | 450 | 0 |
touches
6 source rows · Download touches CSV
| customer TEXT | minute INTEGER | channel TEXT |
|---|---|---|
| U1 | 0 | search |
| U1 | 0 | |
| U1 | 5 | social |
| U2 | 1 | social |
| U2 | 3 | search |
| U3 | 2 |
funnel
10 source rows · Download funnel CSV
| user TEXT | minute INTEGER | step TEXT |
|---|---|---|
| U1 | 0 | visit |
| U1 | 2 | cart |
| U1 | 5 | buy |
| U2 | 0 | buy |
| U2 | 2 | visit |
| U2 | 4 | cart |
| U3 | 1 | visit |
| U3 | 1 | buy |
| U4 | 1 | visit |
| U4 | 2 | cart |
Field dictionary and schema
sales: id INTEGER — Stable source record identifier; not a row position. sku TEXT — Literal business key or category label. Match exactly and retain NULL where present. channel TEXT — Literal business key or category label. Match exactly and retain NULL where present. period INTEGER — Reporting period label1 or2, not an elapsed-time measurement. qty INTEGER — Physical quantity; multiply through assembly paths when the task requires it. price INTEGER — Selling price in integer cents per physical unit. cost INTEGER — Acquisition cost in integer cents per physical unit. returned INTEGER — Number of physically returned units. touches: customer TEXT — Literal business key or category label. Match exactly and retain NULL where present. minute INTEGER — Elapsed UTC minute from the fictional scenario origin. channel TEXT — Literal business key or category label. Match exactly and retain NULL where present. funnel: user TEXT — Literal business key or category label. Match exactly and retain NULL where present. minute INTEGER — Elapsed UTC minute from the fictional scenario origin. step TEXT — Literal business key or category label. Match exactly and retain NULL where present.
A method you can reuse
- For period2, a SKU fails if (price-cost)*100<20*price before returns. Return sku,gross_revenue,margin_pct rounded2 for failures sorted revenue descending,sku.
- For the first output record, sku = D; gross_revenue = 1500; margin_pct = 10.
- Inspect the source grain, keys and ties. Compare each result column with the full worked SQL and expected CSV.
Watch for this wrong turn
Ranking by absolute profit alone can overlook a high-revenue product with an unsustainably thin margin.
Run and check in SQLite
Your SQL runs locally in the existing SQLite worker. The checker compares every column, row, type, value and row order with this fixed output. It accepts equivalent SELECT or WITH queries. Browser storage keeps your SQL on this device when available.
Complete worked SQL and expected output
SELECT sku,qty*price gross_revenue,ROUND(100.0*(price-cost)/price,2) margin_pct FROM sales WHERE period=2 AND (price-cost)*100<20*price ORDER BY gross_revenue DESC,sku;
"sku","gross_revenue","margin_pct" "D","1500","10"Reference SQL · Complete expected CSV · Empty answer CSV
Choose another SQL task · Original data exception cases · Larger workplace projects