DataBrighten

    Student grades sample database for MySQL

    1,000rows · 1 table · 6 questions with answers

    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.

    textnumberdateyes/no

    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.sql

    MySQL Workbench

    File > Open SQL Script, choose the database with USE practice; then Execute.

    Tables and columns

    students 1,000 rows

    ColumnMySQL type
    student_idVARCHAR(10)
    first_nameVARCHAR(20)
    last_nameVARCHAR(20)
    grade_levelINT
    homeroomVARCHAR(10)
    math_scoreINT
    reading_scoreINT
    science_scoreINT
    average_scoreDECIMAL(7,2)
    letter_gradeVARCHAR(10)
    attendance_pctDECIMAL(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_gradestudents
    A78
    B274
    C379
    D226
    F43
    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_levelmathreadingscience
    976.7575.9776.53
    1074.5474.6975.60
    1176.9676.4577.41
    1275.7375.3576.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_idfirst_namelast_namehomeroomaverage_score
    S20546AshleyWright10C100.00
    S20607SarahRobinson9A100.00
    S20898CarolThompson9A100.00
    S20891MichaelLopez11C99.70
    S20028StephanieCook11B98.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_levelhomeroomavg_scorernk
    99C76.861
    99A76.422
    99D76.333
    99B75.964
    1010B76.771
    1010D74.542
    1010C74.373
    1010A74.094
    1111D78.911
    1111A76.692
    1111C76.373
    1111B75.924
    1212C77.621
    1212B75.882

    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

    attendancestudentsavg_score
    90% or more86175.90
    under 90%13976.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.