Data & analytics
Explain a change in reported revenue
revenue_analysis.sql · illustrative excerpt
-- Keep the latest record for each order.
WITH ranked AS (
SELECT *, ROW_NUMBER() OVER (
PARTITION BY order_id
ORDER BY updated_at DESC
) AS version
FROM orders
)
SELECT month, SUM(net_revenue) AS revenue
FROM ranked
WHERE version = 1 AND status = 'paid'
GROUP BY month;Example dialogue showing how working context enters the task.
