Live
No signup
SQL Formatter
Postgres, MySQL, SQLite — pretty.
Raw SQL
Formatted
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 WHERE u.active = true and o.created_at > '2026-01-01' GROUP BY u.id, u.name HAVING count(o.id) > 5 ORDER BY revenue desc LIMIT 100