Store delivery scorecard

Store delivery scorecard

You are a data analyst at a convenience store chain. The head of operations is preparing a weekly summary of online orders and wants a per-store picture: how many orders were placed in total, how many reached the customer, how many were cancelled, and how much revenue came from delivered orders only. The data lives in the orders table: one row per order, status is one of 'delivered', 'cancelled', 'returned', and the order amount is always present (never NULL). Conditional metrics are computed with conditional aggregation: a CASE expression inside an aggregate function. Return columns: - store — store name (text); - total_orders — total number of the store's orders (integer); - delivered_cnt — number of orders with status 'delivered' (integer); - cancelled_cnt — number of orders with status 'cancelled' (integer); - delivered_revenue — sum of amount over delivered orders only, rounded to 2 decimals; 0 if the store has no delivered orders. Sorting: by store ascending. Every store present in the table appears exactly once; the 'returned' status only contributes to total_orders.

Expected output sample

This is what a correct answer looks like — its row count is its own, it doesn't have to match the schema tables. Your answer must use the same column names as this sample — alias them with AS if needed.

storetotal_ordersdelivered_cntcancelled_cntdelivered_revenue
downtown531245.5
harbor422259.5
uptown631206
PostgreSQLv16

Your query result will appear here

Focus radio
Paused · SomaFM · Fluid