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.

Exemplo de resposta esperada

É assim que se parece uma resposta correta: ela tem seu próprio número de linhas e não precisa coincidir com as tabelas do esquema. Sua resposta precisa retornar os mesmos nomes de colunas do exemplo: use AS para renomeá-las se for preciso.

storetotal_ordersdelivered_cntcancelled_cntdelivered_revenue
downtown531245.5
harbor422259.5
uptown631206
PostgreSQLv16
Entre para enviar

O resultado da sua consulta aparecerá aqui

Focus radio
Paused · SomaFM · Fluid