School sample database
Students, courses and enrollments with grades and GPAs.
4 tables · 92 rows · 20 KB
Tables
course_enrollment 5 rows
- course_id integer PK
- course_name text
- enrolled integer
- completed integer
| course_id | course_name | enrolled | completed |
|---|---|---|---|
| 1 | SQL Mastery | 150 | 120 |
| 2 | Python Basics | 200 | 180 |
| 3 | Data Science | 100 | 65 |
courses 15 rows
- course_id integer PK
- course_name text
- credits integer
- department text
| course_id | course_name | credits | department |
|---|---|---|---|
| 1 | SQL Basics | 3 | Computer Science |
| 2 | Python 101 | 3 | Computer Science |
| 3 | Data Structures | 4 | Computer Science |
enrollments 47 rows
- enrollment_id integer PK
- student_id integer → students
- course_id integer → courses
- semester text
- grade text
| enrollment_id | student_id | course_id | semester | grade |
|---|---|---|---|---|
| 1 | 1 | 1 | Fall 2024 | A |
| 2 | 1 | 3 | Fall 2024 | A |
| 3 | 1 | 5 | Fall 2024 | A- |
students 25 rows
- student_id integer PK
- name text
- email text
- grade_level integer
- gpa real
- enrollment_date text
| student_id | name | grade_level | gpa | enrollment_date | |
|---|---|---|---|---|---|
| 1 | Alice Johnson | [email protected] | 12 | 3.9 | 2024-09-01 |
| 2 | Bob Smith | [email protected] | 12 | 3.7 | 2024-09-01 |
| 3 | Carol Williams | [email protected] | 12 | 3.8 | 2024-09-01 |
How the tables connect
- enrollments.course_idcourses.course_id
- enrollments.student_idstudents.student_id
Try a query
Use it on your computer
The SQLite file opens with the sqlite3 command-line tool or any SQLite app:
sqlite3 school.sqlite
.tables
For MySQL, PostgreSQL or SQL Server, run the SQL script instead. It is plain CREATE TABLE and INSERT statements
written for SQLite, so another database may need a small change.
11 practice questions on this database
- Easy Completion Rate as a Percentage Course Completion Percentage Free
- Easy Count Rows per Group Course Enrollment Numbers Free
- Easy Rows Above the Average Students Exceeding Average GPA Free
- Medium Cumulative Sum Over Time Cumulative Student Enrollment Growth Premium
- Medium Ranking With Ties Student GPA Ranking with Ties Premium
- Medium DELETE Rows With a Condition Academic Fresh Start Premium
- Medium Unique Index One Account per Email Premium
- Medium INSERT and UPDATE in One Transaction Enroll and Count, Together Premium
- Medium Subquery vs CTE Courses Above the Average Enrollment Free
- Medium COUNT DISTINCT With GROUP BY Unique Students per Department Free
- Hard DELETE Rows With No Match Remove the Ghost Students Premium
Practice on your iPhone
Query Dojo for iPhone has 85 interview questions, timed mock interviews and a tile builder, so you can write queries without a keyboard.