DataBrighten

    Student grades sample database for DuckDB

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

    A ready-to-run DuckDB script with test scores, averages, letter grades and attendance for grades 9-12. Tested on DuckDB 1.5.6. Updated 19 November 2026.

    textnumberdateyes/no

    Student grades database for DuckDB

    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 DuckDB script: one table and 1,000 rows, with column types chosen for DuckDB, 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 DuckDB 1.5.6 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

    Python

    import duckdb
    con = duckdb.connect("practice.duckdb")
    con.execute(open("students-duckdb.sql").read())

    DuckDB CLI

    duckdb practice.duckdb < students-duckdb.sql

    Tables and columns

    students 1,000 rows

    ColumnDuckDB type
    student_idVARCHAR
    first_nameVARCHAR
    last_nameVARCHAR
    grade_levelINTEGER
    homeroomVARCHAR
    math_scoreINTEGER
    reading_scoreINTEGER
    science_scoreINTEGER
    average_scoreDECIMAL(7,2)
    letter_gradeVARCHAR
    attendance_pctDECIMAL(7,2)

    Practice questions

    answers from DuckDB 1.5.6

    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(math_score), 2) AS math, ROUND(AVG(reading_score), 2) AS reading, ROUND(AVG(science_score), 2) AS science
    FROM students
    GROUP BY grade_level
    ORDER BY grade_level;

    AVG works on integers and decimals directly.

    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(average_score), 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;

    DuckDB supports all standard window functions.

    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(average_score), 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

    DuckDB differences used here

    • AVG works on integers and decimals directly.
    • LIMIT n at the end returns the first n rows.
    • DuckDB supports all standard window functions.