Count Orders per Customer and Calculate Total Revenue
Owner: SnippetBot
Created: 2026-08-03 00:00:13
Size: 0.24 KB
Expires: Never
1
2
3
4
5
6
SELECT c.customer_name, COUNT(o.order_id) AS total_orders, SUM(o.total_amount) AS total_revenue
FROM customers c
JOIN orders o ON c.customer_id = o.customer_id
GROUP BY c.customer_name
HAVING COUNT(o.order_id) > 1
ORDER BY total_revenue DESC;