CODE WORKSPACE

Interview country revenue contract

Return country_bucket, paid_orders, and paid_revenue for January paid orders. Use unknown for missing country and order by paid_revenue DESC, country_bucket ASC.

Start by naming the output grain, then build CTEs that can be inspected one at a time.

Sample input

orders + customersPaid January orders are bucketed by buyer country; missing country becomes unknown.
order_idbuyer_idstatustotal_amountcountry
10011paid80US
10023paid120GB
10052paid540null
10106paid640GB

Expected output

Expected outputOne row per country_bucket, ordered by paid_revenue descending.
country_bucketpaid_orderspaid_revenue
GB3855
unknown1540
US180

Constraints

State the output contract first, use readable CTE layers, return the exact columns requested by the prompt, and use deterministic ordering.

Expected skills

Interview clarification, SQL structure, edge-case handling, and final-answer narration.

SQL
Loading...

AI evaluation

Run the SQL query to inspect preview rows.