New vs returning: Mar–Jun 2025, 'Книги', paid+shipped
Instructions
Consider only paid and shipped orders (status 'paid' or 'shipped'); an order's revenue is the sum of quantity × price over items of the category 'Книги' (categories.name; the price is order_items.price); orders without such items are not counted. A customer's first order is their earliest counted order over the whole history. In the month of their first order the customer is new, in all later months returning. For each month from March 1, 2025 to June 30, 2025 inclusive (by created_at), output month (the first day of the month, type date), new_customers (the number of new customers with orders in that month), new_revenue and returning_revenue (the revenue of orders of new and returning customers, 0 if there are none) and new_share_pct (new_revenue / total revenue of the month × 100, rounded to 1 decimal place). Do not output months without orders. Sort by month.
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.