Best seller on each sales channel in the first quarter
The task
The channel managers want to know what sold best on their channel in the first quarter of 2025. Count units (quantity) on completed orders placed from 2025-01-01 00:00:00 up to, but not including, 2025-04-01 00:00:00.
For each channel, return the product or products with the most units sold in that period. If products tie for the most units, return all of them. A channel with no completed sales in the period does not appear.
Return channel, product_name and units_sold. Sort by channel ascending, then product_name ascending.
Expected output
channelproduct_nameunits_sold- Sorted by channel ascending, then product_name ascending.
- 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
- First order value by acquisition channelmedium
- Months each merchant ranked in the top three for spendmedium
- Products at the three highest price pointseasy
- Repeat contact within 14 days of a first tickethard
- Top three products in each category, with tiesmedium
- Top two artists each month by listening timemedium
Loading the editor and PostgreSQL
Loading the editor and PostgreSQL