File size: 11,840 Bytes
e7cf806 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 |
[
{
"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;"
}
]
|