Krishna Prakash
Initial commit For SQL Practice Platform
e7cf806
[
{
"id": "q1",
"title": "List all students",
"difficulty": "Beginner",
"description": "Retrieve the names and emails of all students.",
"hint": "Use SELECT on the students table.",
"expected_sql": "SELECT name, email FROM students;"
},
{
"id": "q2",
"title": "List all courses",
"difficulty": "Beginner",
"description": "Show all courses with their names and credits.",
"hint": "Use SELECT on the courses table.",
"expected_sql": "SELECT name, credits FROM courses;"
},
{
"id": "q3",
"title": "Find Spring 2023 enrollments",
"difficulty": "Beginner",
"description": "Display student IDs and course IDs for enrollments in Spring 2023.",
"hint": "Use WHERE clause to filter by semester.",
"expected_sql": "SELECT student_id, course_id FROM enrollments WHERE semester = 'Spring 2023';"
},
{
"id": "q4",
"title": "Count total students",
"difficulty": "Beginner",
"description": "Count the total number of students in the system.",
"hint": "Use COUNT() on the students table.",
"expected_sql": "SELECT COUNT(*) AS total_students FROM students;"
},
{
"id": "q5",
"title": "List students in CSE department",
"difficulty": "Beginner",
"description": "Show names and emails of students in the CSE department.",
"hint": "Use WHERE clause to filter by department.",
"expected_sql": "SELECT name, email FROM students WHERE department = 'CSE';"
},
{
"id": "q6",
"title": "List distinct departments",
"difficulty": "Beginner",
"description": "Retrieve all unique departments from the students table.",
"hint": "Use DISTINCT to avoid duplicate departments.",
"expected_sql": "SELECT DISTINCT department FROM students;"
},
{
"id": "q7",
"title": "List courses in CSE department",
"difficulty": "Beginner",
"description": "Show all course names and instructors in the CSE department.",
"hint": "Use WHERE clause to filter by department.",
"expected_sql": "SELECT name, instructor FROM courses WHERE department = 'CSE';"
},
{
"id": "q8",
"title": "List second-year students",
"difficulty": "Beginner",
"description": "Retrieve names and emails of students in year 2.",
"hint": "Use WHERE clause to filter by year.",
"expected_sql": "SELECT name, email FROM students WHERE year = 2;"
},
{
"id": "q9",
"title": "Find instructor for Data Structures",
"difficulty": "Beginner",
"description": "Show the instructor for the 'Data Structures' course.",
"hint": "Use WHERE clause to filter by course name.",
"expected_sql": "SELECT instructor FROM courses WHERE name = 'Data Structures';"
},
{
"id": "q10",
"title": "List student IDs and names",
"difficulty": "Beginner",
"description": "Show all student IDs and their corresponding names.",
"hint": "Use SELECT on the students table.",
"expected_sql": "SELECT student_id, name FROM students;"
},
{
"id": "q11",
"title": "Students and their enrolled courses",
"difficulty": "Intermediate",
"description": "Display student names and the names of courses they are enrolled in.",
"hint": "Join students, enrollments, and courses tables.",
"expected_sql": "SELECT s.name AS student_name, c.name AS course_name FROM enrollments e JOIN students s ON e.student_id = s.student_id JOIN courses c ON e.course_id = c.course_id;"
},
{
"id": "q12",
"title": "Count students per course",
"difficulty": "Intermediate",
"description": "Show the number of students enrolled in each course.",
"hint": "Join enrollments with courses and GROUP BY course name.",
"expected_sql": "SELECT c.name, COUNT(e.student_id) AS student_count FROM enrollments e JOIN courses c ON e.course_id = c.course_id GROUP BY c.name;"
},
{
"id": "q13",
"title": "Students with A grades",
"difficulty": "Intermediate",
"description": "List names of students who received an 'A' grade in any course.",
"hint": "Join enrollments with students and filter by grade.",
"expected_sql": "SELECT DISTINCT s.name FROM enrollments e JOIN students s ON e.student_id = s.student_id WHERE e.grade = 'A';"
},
{
"id": "q14",
"title": "Courses with no enrollments",
"difficulty": "Intermediate",
"description": "Find courses that have no students enrolled.",
"hint": "Use LEFT JOIN and filter for NULL enrollment IDs.",
"expected_sql": "SELECT c.name FROM courses c LEFT JOIN enrollments e ON c.course_id = e.course_id WHERE e.enrollment_id IS NULL;"
},
{
"id": "q15",
"title": "Grades for Operating Systems",
"difficulty": "Intermediate",
"description": "Show student names and grades for the 'Operating Systems' course.",
"hint": "Join enrollments, students, and courses, filter by course name.",
"expected_sql": "SELECT s.name, e.grade FROM enrollments e JOIN students s ON e.student_id = s.student_id JOIN courses c ON e.course_id = c.course_id WHERE c.name = 'Operating Systems';"
},
{
"id": "q16",
"title": "Courses taught by Dr. Anil Kapoor",
"difficulty": "Intermediate",
"description": "List all courses taught by Dr. Anil Kapoor.",
"hint": "Use WHERE clause to filter by instructor.",
"expected_sql": "SELECT name FROM courses WHERE instructor = 'Dr. Anil Kapoor';"
},
{
"id": "q17",
"title": "Students with multiple enrollments",
"difficulty": "Intermediate",
"description": "Find students enrolled in more than one course.",
"hint": "Group by student name and use HAVING clause.",
"expected_sql": "SELECT s.name, COUNT(e.course_id) AS course_count FROM enrollments e JOIN students s ON e.student_id = s.student_id GROUP BY s.name HAVING COUNT(e.course_id) > 1;"
},
{
"id": "q18",
"title": "Total credits per student",
"difficulty": "Intermediate",
"description": "Calculate the total credits each student is enrolled in.",
"hint": "Join enrollments with courses and SUM credits.",
"expected_sql": "SELECT s.name, SUM(c.credits) AS total_credits FROM enrollments e JOIN students s ON e.student_id = s.student_id JOIN courses c ON e.course_id = c.course_id GROUP BY s.name;"
},
{
"id": "q19",
"title": "Courses per department",
"difficulty": "Intermediate",
"description": "Count the number of courses offered by each department.",
"hint": "Group by department in the courses table.",
"expected_sql": "SELECT department, COUNT(course_id) AS course_count FROM courses GROUP BY department;"
},
{
"id": "q20",
"title": "Student enrollment semesters",
"difficulty": "Intermediate",
"description": "List student names and the semesters they are enrolled in.",
"hint": "Join enrollments with students.",
"expected_sql": "SELECT s.name, e.semester FROM enrollments e JOIN students s ON e.student_id = s.student_id;"
},
{
"id": "q21",
"title": "Average GPA per course",
"difficulty": "Advanced",
"description": "Calculate the average GPA per course, mapping grades to numeric values (A=4.0, A-=3.7, B+=3.3, B=3.0).",
"hint": "Use CASE to map grades and AVG for calculation.",
"expected_sql": "SELECT c.name, AVG(CASE e.grade WHEN 'A' THEN 4.0 WHEN 'A-' THEN 3.7 WHEN 'B+' THEN 3.3 WHEN 'B' THEN 3.0 ELSE 0 END) AS avg_gpa FROM enrollments e JOIN courses c ON e.course_id = c.course_id GROUP BY c.name;"
},
{
"id": "q22",
"title": "Top student per course",
"difficulty": "Advanced",
"description": "Find the student with the highest grade in each course.",
"hint": "Use a subquery to find the maximum grade per course.",
"expected_sql": "SELECT s.name, c.name AS course_name, e.grade FROM enrollments e JOIN students s ON e.student_id = s.student_id JOIN courses c ON e.course_id = c.course_id WHERE (e.course_id, e.grade) IN (SELECT course_id, MAX(grade) FROM enrollments GROUP BY course_id);"
},
{
"id": "q23",
"title": "Average credits per department",
"difficulty": "Advanced",
"description": "Calculate the average total credits per student in each department.",
"hint": "Group by student and department, then average credits.",
"expected_sql": "SELECT s.department, AVG(total_credits) AS avg_credits FROM (SELECT s.student_id, s.department, SUM(c.credits) AS total_credits FROM enrollments e JOIN students s ON e.student_id = s.student_id JOIN courses c ON e.course_id = c.course_id GROUP BY s.student_id, s.department) AS temp GROUP BY department;"
},
{
"id": "q24",
"title": "Students not enrolled",
"difficulty": "Advanced",
"description": "List students who are not enrolled in any course.",
"hint": "Use LEFT JOIN and filter for NULL enrollments.",
"expected_sql": "SELECT s.name FROM students s LEFT JOIN enrollments e ON s.student_id = e.student_id WHERE e.enrollment_id IS NULL;"
},
{
"id": "q25",
"title": "Course with highest average GPA",
"difficulty": "Advanced",
"description": "Find the course with the highest average GPA.",
"hint": "Map grades to GPA, group by course, and use LIMIT.",
"expected_sql": "SELECT c.name, AVG(CASE e.grade WHEN 'A' THEN 4.0 WHEN 'A-' THEN 3.7 WHEN 'B+' THEN 3.3 WHEN 'B' THEN 3.0 ELSE 0 END) AS avg_gpa FROM enrollments e JOIN courses c ON e.course_id = c.course_id GROUP BY c.name ORDER BY avg_gpa DESC LIMIT 1;"
},
{
"id": "q26",
"title": "Students enrolled in all CSE courses",
"difficulty": "Advanced",
"description": "List students who have enrolled in every CSE department course.",
"hint": "Compare count of CSE courses with enrolled courses using HAVING.",
"expected_sql": "SELECT s.name FROM enrollments e JOIN students s ON e.student_id = s.student_id JOIN courses c ON e.course_id = c.course_id WHERE c.department = 'CSE' GROUP BY s.name HAVING COUNT(DISTINCT c.course_id) = (SELECT COUNT(*) FROM courses WHERE department = 'CSE');"
},
{
"id": "q27",
"title": "Courses with multi-department students",
"difficulty": "Advanced",
"description": "Find courses with students from more than one department.",
"hint": "Group by course and count distinct departments.",
"expected_sql": "SELECT c.name FROM enrollments e JOIN courses c ON e.course_id = c.course_id JOIN students s ON e.student_id = s.student_id GROUP BY c.name HAVING COUNT(DISTINCT s.department) > 1;"
},
{
"id": "q28",
"title": "Instructor average GPA",
"difficulty": "Advanced",
"description": "Calculate the average GPA for students in courses taught by each instructor.",
"hint": "Join tables, map grades to GPA, and group by instructor.",
"expected_sql": "SELECT c.instructor, AVG(CASE e.grade WHEN 'A' THEN 4.0 WHEN 'A-' THEN 3.7 WHEN 'B+' THEN 3.3 WHEN 'B' THEN 3.0 ELSE 0 END) AS avg_gpa FROM enrollments e JOIN courses c ON e.course_id = c.course_id GROUP BY c.instructor;"
},
{
"id": "q29",
"title": "Students with consistent grades",
"difficulty": "Advanced",
"description": "List students who received the same grade in multiple courses.",
"hint": "Group by student and grade, filter for count > 1.",
"expected_sql": "SELECT s.name, e.grade FROM enrollments e JOIN students s ON e.student_id = s.student_id GROUP BY s.name, e.grade HAVING COUNT(*) > 1;"
},
{
"id": "q30",
"title": "Highest credit course per department",
"difficulty": "Advanced",
"description": "Find the course with the highest credits in each department.",
"hint": "Use a window function or subquery to rank courses by credits.",
"expected_sql": "SELECT department, name, credits FROM (SELECT department, name, credits, RANK() OVER (PARTITION BY department ORDER BY credits DESC) AS rnk FROM courses) AS ranked WHERE rnk = 1;"
}
]