AVG with date arithmetic
What's the average lead time (po_date to gr_date in days) per supplier? Show supplier_name and avg_lead_days. Sort descending.
| 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 |
| Column | Type | Key |
|---|---|---|
| supplier_id | INT | PK |
| supplier_name | TEXT | |
| country | TEXT | |
| tier | INT | |
| category_focus | TEXT | |
| diversity_certified | INT | |
| payment_terms_days | INT | |
| is_preferred | INT |
Each hint you reveal reduces the XP you can earn. Try the query first.
Lead time is the gap between two date columns — date arithmetic returns days.
JOIN POs to suppliers.
Sort descending.