AnalystPath

Top Marketing Channel by Season

SQLMediumMid level~15 min

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.

assets
asset_idasset_namechannel
1Winter BannerSocial
2Denim PromoSocial
3Knife Set CardSearch
spots
spot_idasset_idrun_dateclickscpc
112023-01-15510
222023-01-20415
332023-03-10318

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

Related SQL questions