Top Marketing Channel by Season
Problem
Table: `assets`
```text
+--------------+---------+
| Column Name | Type |
+--------------+---------+
| asset_id | int |
| asset_name | varchar |
| channel | varchar |
+--------------+---------+
asset_id is the primary key for this table.
```
Table: `spots`
```text
+-------------+---------------+
| Column Name | Type |
+-------------+---------------+
| spot_id | int |
| asset_id | int |
| run_date | date |
| clicks | int |
| cpc | decimal(10,2) |
+-------------+---------------+
spot_id is the primary key for this table. cpc is the cost per click.
```
Each ad spot belongs to an asset, and each asset belongs to a marketing channel. Group the calendar into four seasons by month: Winter (12, 1, 2), Spring (3, 4, 5), Summer (6, 7, 8), Fall (9, 10, 11).
For each season, find the single channel with the most total clicks. If two channels tie on clicks, prefer the one with the higher total spend (clicks × cpc); if still tied, prefer the alphabetically earlier channel name.
Return `season`, `channel`, `total_clicks`, and `total_spend`, ordered by `season`.
Tables
Example rows — the live problem includes the full dataset.
| asset_id | asset_name | channel |
|---|---|---|
| 1 | Winter Banner | Social |
| 2 | Denim Promo | Social |
| 3 | Knife Set Card | Search |
| spot_id | asset_id | run_date | clicks | cpc |
|---|---|---|---|---|
| 1 | 1 | 2023-01-15 | 5 | 10 |
| 2 | 2 | 2023-01-20 | 4 | 15 |
| 3 | 3 | 2023-03-10 | 3 | 18 |
Expected output
Your answer should return 4 rows with the columns season, channel, total_clicks, total_spend.
Starter code (SQL)
SELECT *
FROM assets;Solve this SQL question free
Write SQL and run it instantly in your browser — even on your phone. No signup needed to try.
Solution & explanation
Create a free account to unlock the optimal solution, a step-by-step explanation, and the hidden test cases that grade your answer.
Sign up free to unlock