SQLQueryBot
/
SQL Formatter
?
Join waitlist
Paste your SQL
select u.id,u.email,count(o.id) as order_count,sum(o.total) as total_spent from users u join orders o on o.user_id=u.id where o.created_at>=now()-interval '30 days' and o.status='completed' group by u.id,u.email having sum(o.total)>100 order by total_spent desc limit 10;
Dialect
PostgreSQL
MySQL
SQLite
SQL Server
BigQuery
Keywords
UPPERCASE
lowercase
Preserve
Format →
Load example
Copy
SELECT u.id, u.email, count(o.id) AS order_count, sum(o.total) AS total_spent FROM users u JOIN orders o ON o.user_id = u.id WHERE o.created_at >= now() - interval '30 days' AND o.status = 'completed' GROUP BY u.id, u.email HAVING sum(o.total) > 100 ORDER BY total_spent DESC LIMIT 10;