SQL formatter
Make a long query readable.
Make a long query readable.
// Runs in your browser. Nothing you type here is sent anywhere.
Only whitespace and the case of keywords change. The query is not checked: any dialect works, and so does a query with a mistake in it.
SELECT u.id, u.name, count(o.id) AS orders, sum(o.total) AS revenue FROM users u LEFT JOIN orders o ON o.user_id = u.id AND o.status = 'paid' WHERE u.created_at BETWEEN '2026-01-01' AND '2026-12-31' AND (u.country = 'NL' OR u.country = 'BE') GROUP BY u.id, u.name HAVING count(o.id) > 3 ORDER BY revenue DESC LIMIT 20;