You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
%%sql
SELECT date_part('year', order_delivered_customer)::intAS"year",
date_part('month', order_delivered_customer)::intAS"month",
COUNT(*) AS"orders_delivered"FROM orders
WHERE order_status ='delivered'GROUP BY year, month
ORDER BY year, month
%%sql
SELECTcu.customer_state,
cu.customer_city,
COUNT(oi.order_id)
FROM orders AS oi
JOIN customers AS cu ONoi.customer_id=cu.customer_idGROUP BYcu.customer_city, cu.customer_stateORDER BY count DESCLIMIT5
Average difference between estimated and actual delivery by month
%%sql
SELECT month,
AVG(deviation_from_estimated)::realAS difference
FROM(SELECT EXTRACT(MONTH FROM order_purchase)::intAS month,
EXTRACT('days'FROM order_estimated_delivery - order_delivered_customer)::intAS deviation_from_estimated
FROM orders
WHERE order_status ='delivered') AS diff
GROUP BY month
Average difference between order and delivery time by state
%%sql
SELECTdelivery_time.customer_state,
AVG(delivery_time.delivery_in_days)::realAS avg_delivery_time_days
FROM(SELECTcu.customer_state,
EXTRACT('days'FROMod.order_delivered_customer-od.order_purchase)::intAS delivery_in_days
FROM ORDERS AS od
JOIN customers AS cu ONod.customer_id=cu.customer_idWHERE order_status ='delivered') AS delivery_time
GROUP BY customer_state
ORDER BY avg_delivery_time_days DESC