Paid orders, revenue (net of discounts), average and median order value per month, by order date. Orders with a $0 total (samples, promos, replacements; reason not recorded) are excluded.
SELECT strftime(ordered_at, '%Y-%m') AS order_month,
count(*) AS paid_orders,
round(sum(total), 2) AS revenue,
round(avg(total), 2) AS average_order_value,
round(median(total), 2) AS median_order_value
FROM v_orders
WHERE total > 0
GROUP BY ALL
ORDER BY order_month