Advertiser Status Update
Meta 🧠 Hard SQL
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:
    • NEW becomes EXISTING
    • EXISTING stays EXISTING
    • CHURN becomes RESURRECT
    • RESURRECT becomes EXISTING
  • If an advertiser did not pay today:
    • Any status becomes CHURN
  • If a payer is not in the advertiser table (brand new):
    • They get the status NEW

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 JOIN to 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_id in ascending order

Output columns: user_id, new_status

Examples

Example 1:

Input:

advertiser
statususer_id
NEW1
EXISTING2
CHURN3
daily_pay
paiduser_id
501
303
254

Output:
new_statususer_id
EXISTING1
CHURN2
RESURRECT3
NEW4
Quick Solution

Code Environment

Sign in or try as guest to run your code.

Sign In

Track

Question Difficulty Company Access
Need more practice in this area? Explore more questions →