SQL

Natural language to SQL query generation evaluates text-to-query fidelity and schema reasoning. This task is particularly relevant for analytics chat assistants and simplified database interfaces where users need to query data using natural language. Models must understand both the intent behind the question and the structure of the underlying database schema.

75
Duration
6s
Input Tokens
1035
Output Tokens
468
Cost
$0.00
Context
Input
Hi I'm Oscar that enrolled in 2018, I don't remember what courses I completed, can you help me?
Expected output
SELECT DISTINCT c.title FROM users u JOIN enrollments e ON u.user_id = e.user_id JOIN lessons l ON l.course_id = e.course_id JOIN completions cp ON cp.lesson_id = l.lesson_id AND cp.user_id = u.user_id JOIN courses c ON c.course_id = l.course_id WHERE u.name ILIKE '%oscar%' AND DATE_TRUNC('year', e.enrolled_at) = DATE '2018-01-01';
Model output
SELECT c.title
FROM courses c
JOIN enrollments e ON c.course_id = e.course_id
WHERE e.user_id = (SELECT user_id FROM users WHERE name = 'Oscar')
  AND e.enrolled_at >= '2018-01-01' AND e.enrolled_at < '2019-01-01'
  AND e.status = 'completed';