Student grades sample database for MySQL
A ready-to-run MySQL script with test scores, averages, letter grades and attendance for grades 9-12. Tested on MySQL 8.4.13. Updated 19 November 2026.
Student grades database for MySQL
Each row is one fictional high-school student: grade level, homeroom, three test scores, the average, a letter grade from fixed cut-offs and attendance percentage.
This page has it as a MySQL script: one table and 1,000 rows, with column types chosen for MySQL, primary keys. The script drops the table if it exists, creates it and inserts the rows in one transaction, so you can run it again to reset the data. It is the same fictional data, seed 42, as on the student grades dataset page, where it is also available as CSV and Excel.
We loaded this exact file into MySQL 8.4.13 and ran every question below on it; the answers shown are that output. The same questions, written for SQLite, PostgreSQL, MySQL, SQL Server and DuckDB, return the same results on all five.
Load it
mysql client
mysql -u root -p -e "CREATE DATABASE practice"
mysql -u root -p practice < students-mysql.sqlMySQL Workbench
File > Open SQL Script, choose the database with USE practice; then Execute.
Tables and columns
students 1,000 rows
| Column | MySQL type |
|---|---|
| student_id | VARCHAR(10) |
| first_name | VARCHAR(20) |
| last_name | VARCHAR(20) |
| grade_level | INT |
| homeroom | VARCHAR(10) |
| math_score | INT |
| reading_score | INT |
| science_score | INT |
| average_score | DECIMAL(7,2) |
| letter_grade | VARCHAR(10) |
| attendance_pct | DECIMAL(7,2) |
Practice questions
answers from MySQL 8.4.13
How many students got each letter grade?
SQL
SELECT letter_grade, COUNT(*) AS students
FROM students
GROUP BY letter_grade
ORDER BY letter_grade;Result
| letter_grade | students |
|---|---|
| A | 78 |
| B | 274 |
| C | 379 |
| D | 226 |
| F | 43 |
What is the average score in each subject by grade level?
SQL
SELECT grade_level, ROUND(AVG(CAST(math_score AS DECIMAL(18,4))), 2) AS math, ROUND(AVG(CAST(reading_score AS DECIMAL(18,4))), 2) AS reading, ROUND(AVG(CAST(science_score AS DECIMAL(18,4))), 2) AS science
FROM students
GROUP BY grade_level
ORDER BY grade_level;The cast to DECIMAL keeps the average exact before rounding.
Result
| grade_level | math | reading | science |
|---|---|---|---|
| 9 | 76.75 | 75.97 | 76.53 |
| 10 | 74.54 | 74.69 | 75.60 |
| 11 | 76.96 | 76.45 | 77.41 |
| 12 | 75.73 | 75.35 | 76.06 |
Who are the top 5 students by average score?
SQL
SELECT student_id, first_name, last_name, homeroom, average_score
FROM students
ORDER BY average_score DESC, student_id
LIMIT 5;LIMIT n at the end returns the first n rows.
Result
| student_id | first_name | last_name | homeroom | average_score |
|---|---|---|---|---|
| S20546 | Ashley | Wright | 10C | 100.00 |
| S20607 | Sarah | Robinson | 9A | 100.00 |
| S20898 | Carol | Thompson | 9A | 100.00 |
| S20891 | Michael | Lopez | 11C | 99.70 |
| S20028 | Stephanie | Cook | 11B | 98.00 |
How many students scored 90 or more in all three subjects?
SQL
SELECT COUNT(*) AS students
FROM students
WHERE math_score >= 90 AND reading_score >= 90 AND science_score >= 90;Result
| students |
|---|
| 34 |
Rank homerooms by average score within each grade level.
SQL
SELECT grade_level, homeroom, ROUND(AVG(CAST(average_score AS DECIMAL(18,4))), 2) AS avg_score,
RANK() OVER (PARTITION BY grade_level ORDER BY AVG(average_score) DESC) AS rnk
FROM students
GROUP BY grade_level, homeroom
ORDER BY grade_level, rnk, homeroom;Window functions need MySQL 8.0 or later.
Result
| grade_level | homeroom | avg_score | rnk |
|---|---|---|---|
| 9 | 9C | 76.86 | 1 |
| 9 | 9A | 76.42 | 2 |
| 9 | 9D | 76.33 | 3 |
| 9 | 9B | 75.96 | 4 |
| 10 | 10B | 76.77 | 1 |
| 10 | 10D | 74.54 | 2 |
| 10 | 10C | 74.37 | 3 |
| 10 | 10A | 74.09 | 4 |
| 11 | 11D | 78.91 | 1 |
| 11 | 11A | 76.69 | 2 |
| 11 | 11C | 76.37 | 3 |
| 11 | 11B | 75.92 | 4 |
| 12 | 12C | 77.62 | 1 |
| 12 | 12B | 75.88 | 2 |
First 14 of 16 rows.
Do students with attendance under 90% score lower on average?
SQL
SELECT CASE WHEN attendance_pct < 90 THEN 'under 90%' ELSE '90% or more' END AS attendance,
COUNT(*) AS students, ROUND(AVG(CAST(average_score AS DECIMAL(18,4))), 2) AS avg_score
FROM students
GROUP BY CASE WHEN attendance_pct < 90 THEN 'under 90%' ELSE '90% or more' END
ORDER BY attendance;Result
| attendance | students | avg_score |
|---|---|---|
| 90% or more | 861 | 75.90 |
| under 90% | 139 | 76.59 |
MySQL differences used here
- The cast to DECIMAL keeps the average exact before rounding.
- LIMIT n at the end returns the first n rows.
- Window functions need MySQL 8.0 or later.