Advertiser Status Update
Beginner Mode
Objective
Write a SQL query to update the payment status of advertisers based on whether they made a payment today. The status transitions follow these rules:
- If an advertiser paid today:
NEWbecomesEXISTINGEXISTINGstaysEXISTINGCHURNbecomesRESURRECTRESURRECTbecomesEXISTING
- If an advertiser did not pay today:
- Any status becomes
CHURN
- Any status becomes
- If a payer is not in the advertiser table (brand new):
- They get the status
NEW
- They get the status
Table Schema:
- advertiser
| Column | Type | Description |
|---|---|---|
| user_id | INTEGER | Unique identifier for the advertiser |
| status | VARCHAR | Current status ('NEW', 'EXISTING', 'CHURN', 'RESURRECT') |
- daily_pay
| Column | Type | Description |
|---|---|---|
| user_id | INTEGER | Unique identifier for users who paid today |
| paid | DECIMAL | Amount paid |
Task Requirements:
- Use a
FULL OUTER JOINto capture all advertisers and all payers - Apply the status transition rules using conditional logic
- New payers not in the advertiser table should appear with status
NEW - Order results by
user_idin ascending order
Output columns: user_id, new_status
Examples
Example 1:
Output:
Input:
| advertiser | |
|---|---|
| status | user_id |
| NEW | 1 |
| EXISTING | 2 |
| CHURN | 3 |
| daily_pay | |
|---|---|
| paid | user_id |
| 50 | 1 |
| 30 | 3 |
| 25 | 4 |
| new_status | user_id |
|---|---|
| EXISTING | 1 |
| CHURN | 2 |
| RESURRECT | 3 |
| NEW | 4 |
Code Environment
Sign in or try as guest to run your code.
Track
| Question | Difficulty | Company | Access |
|---|
Need more practice in this area? Explore more questions →
Meta