|
[ |
|
{ |
|
"id": "q1", |
|
"title": "List female patients", |
|
"difficulty": "Beginner", |
|
"description": "Retrieve the names and contact details of all female patients.", |
|
"hint": "Use a WHERE clause to filter by gender.", |
|
"expected_sql": "SELECT name, contact FROM patients WHERE gender = 'Female';" |
|
}, |
|
{ |
|
"id": "q2", |
|
"title": "Find appointments on specific date", |
|
"difficulty": "Beginner", |
|
"description": "Show all appointments scheduled on July 10, 2023.", |
|
"hint": "Use a WHERE clause with date comparison.", |
|
"expected_sql": "SELECT appointment_id, patient_id, doctor_id, appointment_date FROM appointments WHERE appointment_date = '2023-07-10';" |
|
}, |
|
{ |
|
"id": "q3", |
|
"title": "List cardiologists", |
|
"difficulty": "Beginner", |
|
"description": "Retrieve the names and contact details of all doctors with the Cardiologist specialty.", |
|
"hint": "Use a WHERE clause to filter by specialty.", |
|
"expected_sql": "SELECT name, contact FROM doctors WHERE specialty = 'Cardiologist';" |
|
}, |
|
{ |
|
"id": "q4", |
|
"title": "Patients born before 1995", |
|
"difficulty": "Beginner", |
|
"description": "Show the names and dates of birth of patients born before January 1, 1995.", |
|
"hint": "Use a WHERE clause with date comparison on dob.", |
|
"expected_sql": "SELECT name, dob FROM patients WHERE dob < '1995-01-01';" |
|
}, |
|
{ |
|
"id": "q5", |
|
"title": "List unique diagnoses", |
|
"difficulty": "Beginner", |
|
"description": "Retrieve all unique diagnoses from the appointments table.", |
|
"hint": "Use DISTINCT to avoid duplicate diagnoses.", |
|
"expected_sql": "SELECT DISTINCT diagnosis FROM appointments;" |
|
}, |
|
{ |
|
"id": "q6", |
|
"title": "Appointments for doctor ID 1", |
|
"difficulty": "Beginner", |
|
"description": "Show all appointments for the doctor with ID 1.", |
|
"hint": "Use a WHERE clause to filter by doctor_id.", |
|
"expected_sql": "SELECT appointment_id, patient_id, appointment_date FROM appointments WHERE doctor_id = 1;" |
|
}, |
|
{ |
|
"id": "q7", |
|
"title": "List patient names and genders", |
|
"difficulty": "Beginner", |
|
"description": "Show all patient names and their genders.", |
|
"hint": "Select name and gender from the patients table.", |
|
"expected_sql": "SELECT name, gender FROM patients;" |
|
}, |
|
{ |
|
"id": "q8", |
|
"title": "Appointments in August 2023", |
|
"difficulty": "Beginner", |
|
"description": "Retrieve all appointments scheduled in August 2023.", |
|
"hint": "Use a WHERE clause with LIKE for appointment_date.", |
|
"expected_sql": "SELECT appointment_id, patient_id, doctor_id, appointment_date FROM appointments WHERE appointment_date LIKE '2023-08%';" |
|
}, |
|
{ |
|
"id": "q9", |
|
"title": "List doctors and specialties", |
|
"difficulty": "Beginner", |
|
"description": "Show all doctor names and their specialties.", |
|
"hint": "Select name and specialty from the doctors table.", |
|
"expected_sql": "SELECT name, specialty FROM doctors;" |
|
}, |
|
{ |
|
"id": "q10", |
|
"title": "Patients with Routine Checkup", |
|
"difficulty": "Beginner", |
|
"description": "Retrieve the names of patients with a diagnosis of 'Routine Checkup'.", |
|
"hint": "Join patients and appointments, filter by diagnosis.", |
|
"expected_sql": "SELECT p.name FROM patients p JOIN appointments a ON p.patient_id = a.patient_id WHERE a.diagnosis = 'Routine Checkup';" |
|
}, |
|
{ |
|
"id": "q11", |
|
"title": "Appointments per doctor", |
|
"difficulty": "Intermediate", |
|
"description": "Show the number of appointments for each doctor, including those with zero appointments.", |
|
"hint": "Use a LEFT JOIN and GROUP BY doctor name.", |
|
"expected_sql": "SELECT d.name, COUNT(a.appointment_id) AS appointment_count FROM doctors d LEFT JOIN appointments a ON d.doctor_id = a.doctor_id GROUP BY d.name;" |
|
}, |
|
{ |
|
"id": "q12", |
|
"title": "Patients with multiple appointments", |
|
"difficulty": "Intermediate", |
|
"description": "Find patients who have more than one appointment.", |
|
"hint": "Join patients and appointments, use GROUP BY and HAVING clause.", |
|
"expected_sql": "SELECT p.name, COUNT(a.appointment_id) AS appointment_count FROM patients p JOIN appointments a ON p.patient_id = a.patient_id GROUP BY p.name HAVING COUNT(a.appointment_id) > 1;" |
|
}, |
|
{ |
|
"id": "q13", |
|
"title": "Appointments by doctor specialty", |
|
"difficulty": "Intermediate", |
|
"description": "Count the number of appointments for each doctor specialty.", |
|
"hint": "Join doctors and appointments, then GROUP BY specialty.", |
|
"expected_sql": "SELECT d.specialty, COUNT(a.appointment_id) AS total_appointments FROM doctors d JOIN appointments a ON d.doctor_id = a.doctor_id GROUP BY d.specialty;" |
|
}, |
|
{ |
|
"id": "q14", |
|
"title": "Patient and doctor appointment details", |
|
"difficulty": "Intermediate", |
|
"description": "Show patient names, doctor names, and appointment dates for all appointments.", |
|
"hint": "Join patients, doctors, and appointments tables.", |
|
"expected_sql": "SELECT p.name AS patient_name, d.name AS doctor_name, a.appointment_date FROM appointments a JOIN patients p ON a.patient_id = p.patient_id JOIN doctors d ON a.doctor_id = d.doctor_id;" |
|
}, |
|
{ |
|
"id": "q15", |
|
"title": "Diagnoses by patient gender", |
|
"difficulty": "Intermediate", |
|
"description": "Count the number of appointments for each diagnosis, grouped by patient gender.", |
|
"hint": "Join patients and appointments, GROUP BY gender and diagnosis.", |
|
"expected_sql": "SELECT p.gender, a.diagnosis, COUNT(a.appointment_id) AS appointment_count FROM patients p JOIN appointments a ON p.patient_id = a.patient_id GROUP BY p.gender, a.diagnosis;" |
|
}, |
|
{ |
|
"id": "q16", |
|
"title": "Doctors with no appointments", |
|
"difficulty": "Intermediate", |
|
"description": "List doctors who have not had any appointments.", |
|
"hint": "Use a LEFT JOIN and check for NULL in the appointments table.", |
|
"expected_sql": "SELECT d.name FROM doctors d LEFT JOIN appointments a ON d.doctor_id = a.doctor_id WHERE a.appointment_id IS NULL;" |
|
}, |
|
{ |
|
"id": "q17", |
|
"title": "Patients seen by multiple doctors", |
|
"difficulty": "Intermediate", |
|
"description": "Find patients who have appointments with more than one distinct doctor.", |
|
"hint": "Join patients and appointments, group by patient, and use HAVING clause.", |
|
"expected_sql": "SELECT p.name, COUNT(DISTINCT a.doctor_id) AS doctor_count FROM patients p JOIN appointments a ON p.patient_id = a.patient_id GROUP BY p.name HAVING COUNT(DISTINCT a.doctor_id) > 1;" |
|
}, |
|
{ |
|
"id": "q18", |
|
"title": "Appointments in July 2023", |
|
"difficulty": "Intermediate", |
|
"description": "List all appointments between July 1, 2023, and July 31, 2023.", |
|
"hint": "Use a BETWEEN clause for the date range.", |
|
"expected_sql": "SELECT appointment_id, patient_id, doctor_id, appointment_date FROM appointments WHERE appointment_date BETWEEN '2023-07-01' AND '2023-07-31';" |
|
}, |
|
{ |
|
"id": "q19", |
|
"title": "Most common diagnosis", |
|
"difficulty": "Intermediate", |
|
"description": "Find the diagnosis with the highest number of appointments.", |
|
"hint": "Group by diagnosis, count appointments, and use LIMIT.", |
|
"expected_sql": "SELECT diagnosis, COUNT(appointment_id) AS diagnosis_count FROM appointments GROUP BY diagnosis ORDER BY diagnosis_count DESC LIMIT 1;" |
|
}, |
|
{ |
|
"id": "q20", |
|
"title": "Unique patients by specialty", |
|
"difficulty": "Intermediate", |
|
"description": "Show the number of unique patients seen by each doctor specialty.", |
|
"hint": "Join doctors and appointments, use COUNT and DISTINCT, group by specialty.", |
|
"expected_sql": "SELECT d.specialty, COUNT(DISTINCT a.patient_id) AS unique_patients FROM doctors d JOIN appointments a ON d.doctor_id = a.doctor_id GROUP BY d.specialty;" |
|
}, |
|
{ |
|
"id": "q21", |
|
"title": "Patient age at appointment", |
|
"difficulty": "Advanced", |
|
"description": "Calculate the age of each patient at the time of their appointment.", |
|
"hint": "Join patients and appointments, use JULIANDAY for age calculation.", |
|
"expected_sql": "SELECT p.name, a.appointment_date, ROUND((JULIANDAY(a.appointment_date) - JULIANDAY(p.dob)) / 365.25, 1) AS age FROM patients p JOIN appointments a ON p.patient_id = a.patient_id;" |
|
}, |
|
{ |
|
"id": "q22", |
|
"title": "Most active doctor", |
|
"difficulty": "Advanced", |
|
"description": "Find the doctor with the highest number of appointments.", |
|
"hint": "Join doctors and appointments, group by doctor name, and use LIMIT.", |
|
"expected_sql": "SELECT d.name, COUNT(a.appointment_id) AS appointment_count FROM doctors d JOIN appointments a ON d.doctor_id = a.doctor_id GROUP BY d.name ORDER BY appointment_count DESC LIMIT 1;" |
|
}, |
|
{ |
|
"id": "q23", |
|
"title": "Patients seen by Cardiologist", |
|
"difficulty": "Advanced", |
|
"description": "List all patients who have seen a Cardiologist, including their diagnoses.", |
|
"hint": "Join all tables and filter by doctor specialty.", |
|
"expected_sql": "SELECT DISTINCT p.name, a.diagnosis FROM patients p JOIN appointments a ON p.patient_id = a.patient_id JOIN doctors d ON a.doctor_id = d.doctor_id WHERE d.specialty = 'Cardiologist';" |
|
}, |
|
{ |
|
"id": "q24", |
|
"title": "Diagnosis frequency by doctor", |
|
"difficulty": "Advanced", |
|
"description": "Show the number of times each diagnosis was made by each doctor.", |
|
"hint": "Join doctors and appointments, group by doctor name and diagnosis.", |
|
"expected_sql": "SELECT d.name, a.diagnosis, COUNT(a.appointment_id) AS diagnosis_count FROM doctors d JOIN appointments a ON d.doctor_id = a.doctor_id GROUP BY d.name, a.diagnosis;" |
|
}, |
|
{ |
|
"id": "q25", |
|
"title": "Appointments per month", |
|
"difficulty": "Advanced", |
|
"description": "Show the number of appointments per month in 2023.", |
|
"hint": "Use STRFTIME to extract the month and GROUP BY.", |
|
"expected_sql": "SELECT STRFTIME('%Y-%m', appointment_date) AS month, COUNT(appointment_id) AS appointment_count FROM appointments GROUP BY month;" |
|
}, |
|
{ |
|
"id": "q26", |
|
"title": "Youngest patient per doctor", |
|
"difficulty": "Advanced", |
|
"description": "Find the youngest patient seen by each doctor.", |
|
"hint": "Join tables, calculate age using JULIANDAY, and group by doctor.", |
|
"expected_sql": "SELECT d.name, p.name AS patient_name, MIN(ROUND((JULIANDAY(a.appointment_date) - JULIANDAY(p.dob)) / 365.25, 1)) AS age FROM doctors d JOIN appointments a ON d.doctor_id = a.doctor_id JOIN patients p ON a.patient_id = p.patient_id GROUP BY d.name;" |
|
}, |
|
{ |
|
"id": "q27", |
|
"title": "Patients with multiple specialties", |
|
"difficulty": "Advanced", |
|
"description": "List patients who have seen doctors from more than one specialty.", |
|
"hint": "Join tables, count distinct specialties, and use HAVING clause.", |
|
"expected_sql": "SELECT p.name, COUNT(DISTINCT d.specialty) AS specialty_count FROM patients p JOIN appointments a ON p.patient_id = a.patient_id JOIN doctors d ON a.doctor_id = d.doctor_id GROUP BY p.name HAVING COUNT(DISTINCT d.specialty) > 1;" |
|
}, |
|
{ |
|
"id": "q28", |
|
"title": "Unique diagnoses per doctor", |
|
"difficulty": "Advanced", |
|
"description": "Show the number of unique diagnoses made by each doctor.", |
|
"hint": "Join doctors and appointments, use COUNT and DISTINCT, group by doctor name.", |
|
"expected_sql": "SELECT d.name, COUNT(DISTINCT a.diagnosis) AS unique_diagnoses FROM doctors d JOIN appointments a ON d.doctor_id = a.doctor_id GROUP BY d.name;" |
|
}, |
|
{ |
|
"id": "q29", |
|
"title": "Patients not seen by Neurologist", |
|
"difficulty": "Advanced", |
|
"description": "List patients who have never been seen by a Neurologist.", |
|
"hint": "Use NOT IN or LEFT JOIN to exclude patients with Neurologist appointments.", |
|
"expected_sql": "SELECT p.name FROM patients p WHERE p.patient_id NOT IN (SELECT a.patient_id FROM appointments a JOIN doctors d ON a.doctor_id = d.doctor_id WHERE d.specialty = 'Neurologist');" |
|
}, |
|
{ |
|
"id": "q30", |
|
"title": "Earliest and latest appointment per patient", |
|
"difficulty": "Advanced", |
|
"description": "Show the earliest and latest appointment dates for each patient with appointments.", |
|
"hint": "Join patients and appointments, use MIN and MAX on appointment_date.", |
|
"expected_sql": "SELECT p.name, MIN(a.appointment_date) AS earliest_appointment, MAX(a.appointment_date) AS latest_appointment FROM patients p JOIN appointments a ON p.patient_id = a.patient_id GROUP BY p.name;" |
|
} |
|
] |
|
|