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.

75
Duration
8s
Input Tokens
1038
Output Tokens
263
Cost
$0.00
Context
Input
I am in the class with teacher Amanda Svensson, I can't find the link to the video for the last lesson. Can you provide me with it?
Expected output
SELECT l.video_url FROM lessons l JOIN courses c ON l.course_id = c.course_id JOIN users u ON c.instructor_id = u.user_id WHERE u.name = 'Amanda Svensson' AND l.order_index = (SELECT MAX(order_index) FROM lessons l2 WHERE l2.course_id = c.course_id);
Model output
WITH amanda_courses AS (
    SELECT c.course_id
    FROM users u
    JOIN courses c ON u.user_id = c.instructor_id
    WHERE u.name = 'Amanda Svensson'
),
last_lesson AS (
    SELECT l.lesson_id, l.video_url, l.order_index
    FROM lessons l
    JOIN amanda_courses ac ON l.course_id = ac.course_id
    ORDER BY l.order_index DESC
    LIMIT 1
)
SELECT video_url
FROM last_lesson;