SELECT c.name,↵
COUNT(o.id) AS orders,↵
SUM(o.total) AS spent↵
FROM customers AS c↵
JOIN orders AS o ON o.customer_id = c.id↵
WHERE o.created_at >= DATE '2026-01-01'↵
GROUP BY c.name↵
HAVING SUM(o.total) > 500↵
ORDER BY spent DESC↵
LIMIT 10;
Click here or press any key to type