Write a SQL query to analyze Taboola campaign operations performance by publisher and advertiser segment, including joins across tables, monthly aggregation, and a ranking of the worst-performing segments.
Use the provided campaign and daily metrics data for January and February 2025. Rank segments within each publisher and month by return on spend, with the weakest performance ranked first.
month, publisher_name, segment_name, impressions, clicks, conversions, spend, revenue, return_on_spend, and worst_rank.| Column | Type | Description |
|---|---|---|
| publisher_idPK | INT | Unique publisher identifier |
| publisher_name | VARCHAR(100) | Publisher display name |
| region | VARCHAR(50) | Publisher operating region |
| Column | Type | Description |
|---|---|---|
| segment_idPK | INT | Unique advertiser segment identifier |
| segment_name | VARCHAR(100) | Advertiser segment name |
| segment_type | VARCHAR(50) | Segment classification |
| Column | Type | Description |
|---|---|---|
| campaign_idPK | INT | Unique campaign identifier |
| publisher_id | INT | Publisher running the campaign |
| segment_id | INT | Advertiser segment targeted by the campaign |
| campaign_name | VARCHAR(120) | Campaign display name |
| status | VARCHAR(20) | Campaign lifecycle status |
| Column | Type | Description |
|---|---|---|
| metric_idPK | INT | Unique daily metric identifier |
| campaign_id | INT | Campaign associated with the metrics |
| metric_date | DATE | Date of the recorded metrics |
| impressions | INT | Number of served impressions |
| clicks | INT | Number of ad clicks |
| conversions | INT | Number of conversions |
| spend | NUMERIC(12,2) | Campaign spend |
| revenue | NUMERIC(12,2) | Attributed campaign revenue |