Above city average x1.5: no cancellations, Jul–Sep 2025
Instructions
A customer's spending is the sum of quantity * order_items.price over the items of their orders with a status other than 'cancelled' created on or after July 1, 2025 and strictly before October 1, 2025. Customers without a city (city IS NULL) are not considered in the comparison; only customers with such spending take part in the average (customers without orders in the period do not count as zero). A city's average spending is the average spending of these customers of the city. Find customers whose spending is strictly greater than the average of their city, multiplied by 1.5. Output id, name, city, spend and city_avg, the city average, rounded to 2 decimal places. Row order does not matter.
Hints
Each next one is more detailed and costs more
Query
Result
Click Run to see the query result, or Check to submit your solution.
Dataset schema
Table relationships
- N:1Many-to-one
order_items.→order_id orders.id - N:1Many-to-one
order_items.→product_id products.id - N:1Many-to-one
orders.→customer_id customers.id - N:1Many-to-one
products.→category_id categories.id
Table data
Select a table in the diagram or list to view its rows.