First order value by acquisition channel
The task
Marketing wants to know which channel brings in the biggest first orders. A customer's first order is their earliest order with status completed. If two completed orders have the same ordered_at, the one with the lower order_id is first. Customers with no completed order are ignored.
The value of an order is the sum of quantity * unit_price over its rows in order_items (shipping is not included).
Group customers by the channel of their first order. Return channel, customers (how many customers had their first order on that channel) and avg_first_order_value (the average value of those first orders, rounded to 2 decimal places). Sort by channel ascending.
Expected output
channelcustomersavg_first_order_value- Sorted by channel ascending.
- Numbers rounded to 2 decimal places.
- Checked on the sample and on 2 hidden datasets. How grading works
Tables Online store · click a name to insert it
customers150 rows in the sample
One row per customer account. Key: customer_id.
| int | Unique id. | |
| text | Name on the account. | |
| text | NULL when the customer never gave one (marketplace buyers). | |
| text | Two-letter country code. | |
| date | Day the account was created. | |
| text | organic, paid_search, social, referral or email. NULL when unknown. |
products36 rows in the sample
The catalog. Key: product_id.
| int | Unique id. | |
| text | Display name. | |
| text | Kitchen, Home, Outdoors, Books, Beauty or Toys. | |
| numeric(10,2) | Current list price in USD. | |
| date | First day on sale. |
orders700 rows in the sample
One row per order. Key: order_id.
| int | Unique id. | |
| int | Who placed it. | |
| timestamp | When it was placed (UTC). | |
| text | completed, cancelled or refunded. | |
| text | web, app or marketplace. | |
| numeric(10,2) | Shipping charged, USD. | |
| text | Coupon used, NULL if none. |
order_items1,266 rows in the sample
One row per product in an order. Key: order_id, product_id.
| int | The order. | |
| int | The product. | |
| int | Units bought. | |
| numeric(10,2) | Price paid per unit, after discounts, USD. |
returns79 rows in the sample
Items sent back. Key: return_id.
| int | Unique id. | |
| int | The original order. | |
| int | The product returned. | |
| date | Day the return arrived. | |
| int | Units returned. | |
| text | damaged, wrong_item, not_as_described or changed_mind. NULL when not given. |
Related questions
- Top three products in each category, with tiesmedium
- Best seller on each sales channel in the first quartermedium
- Favourite spending category per customer, counted by segmenthard
- How far each artist climbed or fell from April to Mayhard
- Listener quartiles by May listening timemedium
- Months each merchant ranked in the top three for spendmedium
Loading the editor and PostgreSQL
Loading the editor and PostgreSQL