Last Updated: May 10, 2026
For this exercise, we will work with below data:
Find all active subscriptions (where end_date is NULL). Show subscription_id, user_id, plan, and start_date, ordered by subscription_id.
Show each user's username and timezone, replacing NULL timezones with the literal string 'Not set'. Order by user_id.
Calculate the net amount for each payment as amount - refund_amount. Treat missing refunds as zero so the result is never NULL. Show payment_id, amount, refund_amount, and net_amount, ordered by payment_id.
Count three things in a single query against the streams table: the total number of stream rows, the number of streams with a non-NULL country, and the number of distinct non-NULL countries.
For each user who has at least one payment, return user_id, net_amount (SUM(amount) minus the total refund where missing refunds are treated as 0), and refund_ratio (total refunds divided by total amount, guarded against division by zero, with NULL ratios shown as 0). Round refund_ratio to 2 decimals. Order by user_id.