Browse
textChatGPT · GPT-4o

Turn plain English into SQL

The prompt

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.

Example output

output
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