How would you answer SQL questions on joins and CTEs, and Python questions using pandas for string manipulation?
For the SQL portion, write a query that analyzes merchants, customers, payments, and payment events for Q1 2025. The result should combine payment totals with repeat-customer and month-over-month metrics.
Output
- One row per merchant, including merchants without qualifying payments.
- Columns:
merchant_name, total_success_amount, active_customers, repeat_customers, latest_success_date, and avg_monthly_change.
- Include only successful payments from Q1 2025 for payment metrics. Order by
total_success_amount descending, then merchant_name ascending.
Output details
- Treat Q1 2025 as dates from
2025-01-01 inclusive through 2025-04-01 exclusive.
- Define
active_customers as distinct non-NULL customers with successful payments during Q1 2025.
- Define
repeat_customers as customers with successful payments in multiple distinct Q1 months for the same merchant.
- Compute
avg_monthly_change from consecutive monthly customer totals, average qualifying differences, use 0 when none, and round to 2 decimals.
- Use
0 for merchants without qualifying payments, and leave latest_success_date as NULL when none exists.
- Treat merchants as distinct records by merchant identity, retaining separate rows when merchant names repeat.