account_history has one row per advertiser and active year (advertiser_id, activity_year); duplicates are possible. The current year is the latest activity_year in the table and the previous year is current - 1. Classify every advertiser: 'Existing' if active in both the current and previous year; 'Resurrected' if active in the current year, not in the previous year, but in some earlier year; 'New' if the current year is their only active year; 'Churned' if not active in the current year. Output columns: advertiser_id, status. Order by advertiser_id ascending.
| Column | Type |
|---|---|
| advertiser_id | INTEGER |
| activity_year | INTEGER |
| advertiser_id | activity_year |
|---|---|
| 1 | 2025 |
| 1 | 2026 |
| 2 | 2025 |
| 3 | 2026 |
| 4 | 2024 |
| 4 | 2026 |
| advertiser_id | status |
|---|---|
| 1 | Existing |
| 2 | Churned |
| 3 | New |
| 4 | Resurrected |
Solve it in the live editor on this page — run on sample data, then submit against hidden tests.
‹ Weighted Search Volume Median · Consecutive Compliance Filings ›
{{ totalCount }} questions in the style asked at Amazon, Microsoft, Google, Meta, Flipkart and more — {{ hardPct }}% Hard. Write SQL in a real database engine in your browser, run it on sample data, then evaluate against hidden tests.
Company tags show where this type of question is commonly reported in interviews. Questions, data and solutions are written by TechTown.
{{ cur.statement }}
No submissions yet. Press Evaluate to submit your query.
{{ solutionSql }}
{{ out.error }}
You have solved your 3 free questions — nice work! Log in (free) to unlock all 150 questions, keep your streak and appear on the leaderboard.