SQL Generation

Turn plain-English questions into correct SQL against a schema. The skill behind analytics chat, natural-language dashboards, and 'just ask the database' interfaces.

25
Duration
6s
Input Tokens
1194
Output Tokens
163
Cost
$0.00
Context
Input
Who are the instructors making the most money from enrollments? Give me a list (instructor_name) and total earnings (total_earnings) sorted by their earnings please.
Expected output
SELECT u.name as instructor_name, SUM(p.amount) AS total_earnings FROM payments p JOIN enrollments e ON p.enrollment_id = e.enrollment_id JOIN courses c ON e.course_id = c.course_id JOIN users u ON c.instructor_id = u.user_id GROUP BY u.name ORDER BY total_earnings DESC;
Model output
SELECT u.name, SUM(p.amount) as total_earnings 
FROM enrollments e 
JOIN payments p ON e.enrollment_id = p.enrollment_id 
JOIN users u ON e.instructor_id = u.user_id 
GROUP BY u.name 
ORDER BY total_earnings DESC;