423. New vs Returning Customer Revenue Split

Hard Growth Business Intelligence
Query Rules
  • The query columns and order must match the expected result schema.
  • NULL values should be handled appropriately where applicable.
  • The grader compares output values and sorting order to evaluate.

Schema Browser

Click a table's header to toggle expand/collapse.
locations
3 cols
departments
3 cols
employees
6 cols
orders
6 cols

Reference Solution

Expected SQL
WITH first_order AS (SELECT customer_name, MIN(strftime('%Y-%m', order_date)) AS first_month FROM orders GROUP BY customer_name) SELECT strftime('%Y-%m', o.order_date) AS month, SUM(CASE WHEN strftime('%Y-%m', o.order_date) = f.first_month THEN o.amount ELSE 0 END) AS new_customer_revenue, SUM(CASE WHEN strftime('%Y-%m', o.order_date) != f.first_month THEN o.amount ELSE 0 END) AS returning_customer_revenue FROM orders o JOIN first_order f ON o.customer_name = f.customer_name GROUP BY month ORDER BY month;
SQL Editor
Ctrl+Enter to run
Console Output

Console Terminal

Write your query and click "Run Query" (Ctrl + Enter) to see results and testcase validation.