Given a `orders(id, user_id, total, created_at)` table, write SQL for the top 5 users by total spend in the last 30 days.
SELECT user_id, SUM(total) AS spend FROM orders WHERE created_at >= NOW() - INTERVAL '30 days' GROUP BY user_id ORDER BY spend DESC LIMIT 5;
Written for
ChatGPT