AVG of date diff with multiple stages
Average req-to-PO cycle time and PO-to-GR cycle time across closed POs. Two columns.
| Column | Type | Key |
|---|---|---|
| po_id | INT | PK |
| supplier_id | INT | FK → dim_suppliers |
| category_id | INT | FK → dim_categories |
| contract_id | INT | FK → dim_contracts |
| req_date | TEXT | |
| po_date | TEXT | |
| ack_date | TEXT | |
| asn_date | TEXT | |
| gr_date | TEXT | |
| invoice_date | TEXT | |
| qty_ordered | INT | |
| qty_received | INT | |
| unit_price | REAL | |
| contracted_price | REAL | |
| status | TEXT |
Each hint you reveal reduces the XP you can earn. Try the query first.
Two-stage cycle time: each stage is the gap between two dates, averaged across closed POs.
Compute the gap between two date columns and average it — repeat per stage of the cycle.
WHERE status = 'CLOSED'.