← Practice

ARPU/ARPPU: May–Jul 2025, 'Книги', excl. cancelled

Level: SeniorTopic: Retention, funnels, cohorts200 XP

Instructions

Consider only non-cancelled orders (status <> 'cancelled') created from May 1, 2025 to July 31, 2025 inclusive; revenue is the sum of quantity × price of items of the category 'Книги' (categories.name) in these orders (the price is order_items.price). A city's customers are all customers (customers) with registered_at strictly earlier than August 1, 2025; customers without a city belong to the group 'не указан'. A paying customer is a customer with non-zero such revenue. For each city, output city, customers (the number of customers in the city), payers (the number of paying customers), revenue (their total revenue, 0 if there is none), arpu (revenue / customers) and arppu (revenue / payers; NULL if there are no payers); round arpu and arppu to 2 decimal places. The revenue of customers who registered later is not counted. Sort by city.

Hints

Each next one is more detailed and costs more

Log in to open hints

Query

Result

Click Run to see the query result, or Check to submit your solution.

Dataset schema

order_items.order_id (0…N) ↔ orders.id (1…1)order_items.product_id (0…N) ↔ products.id (1…1)orders.customer_id (0…N) ↔ customers.id (1…1)products.category_id (0…N) ↔ categories.id (1…1)categoriesPKidintegercustomersPKidintegerimport_logPKidintegerorder_itemsPKFKorder_idintegerPKFKproduct_idintegerordersPKidintegerFKcustomer_idintegerproductsPKidintegerFKcategory_idinteger
Exactly oneZero or oneZero or more
Table relationships
  • N:1Many-to-oneorder_items.order_id → orders.id
  • N:1Many-to-oneorder_items.product_id → products.id
  • N:1Many-to-oneorders.customer_id → customers.id
  • N:1Many-to-oneproducts.category_id → categories.id

Table data

PostgreSQL

Select a table in the diagram or list to view its rows.

Dataset schema