Skip to content

Lecture 20: Mini-Project – Student Grades Part 1

  • by
  • 3 min read
Mini Project Student Grades

This lecture begins a mini-project to analyze student grades.

Let’s begin our second mini-project. This time, we will create a database to store student grades for different subjects. This project is designed to use the aggregate functions and the GROUP BY clause we have just learned.

Project Goal

Our goal is to create a table that stores individual grades for students. We then want to perform some basic analysis, such as finding the average grade for each student and the average grade for each subject.

Step 1: Designing the Table

We need to store the following information for each grade entry:

  • A unique ID for the grade entry.
  • The name of the student.
  • The subject.
  • The grade or score they received (out of 100).

Here is the plan for our `Grades` table:

  • GradeIDINTEGER PRIMARY KEY – The unique identifier.
  • StudentNameTEXT – The name of the student.
  • SubjectTEXT – The name of the subject (e.g., ‘Math’, ‘History’).
  • ScoreINTEGER – The score the student received (0-100).

Step 2: Creating and Populating the Table

Now, let’s write the SQL to create the `Grades` table and insert some data. We will add grades for three students: Alice, Bob, and Charlie.

CREATE TABLE Grades (
    GradeID INTEGER PRIMARY KEY,
    StudentName TEXT,
    Subject TEXT,
    Score INTEGER
);

-- Alice's Grades
INSERT INTO Grades (StudentName, Subject, Score) VALUES ('Alice', 'Math', 90);
INSERT INTO Grades (StudentName, Subject, Score) VALUES ('Alice', 'History', 85);
INSERT INTO Grades (StudentName, Subject, Score) VALUES ('Alice', 'Science', 92);

-- Bob's Grades
INSERT INTO Grades (StudentName, Subject, Score) VALUES ('Bob', 'Math', 78);
INSERT INTO Grades (StudentName, Subject, Score) VALUES ('Bob', 'History', 88);
INSERT INTO Grades (StudentName, Subject, Score) VALUES ('Bob', 'Science', 72);

-- Charlie's Grades
INSERT INTO Grades (StudentName, Subject, Score) VALUES ('Charlie', 'Math', 95);
INSERT INTO Grades (StudentName, Subject, Score) VALUES ('Charlie', 'History', 91);
INSERT INTO Grades (StudentName, Subject, Score) VALUES ('Charlie', 'Science', 89);

Run these commands to create and populate your table. We now have a good set of data to work with.

Mini Project Student Grades
Mini Project Student Grades
In the Next Lecture…

In the second part of this project, we will use our new data analysis skills. We will write queries to calculate the average score for each student, find the highest and lowest grade in each subject, and count how many tests each student has taken. This will put GROUP BY and our aggregate functions to a real-world test.

Lecture 19: Grouping Data with GROUP BY

Najeeb Alam

Najeeb Alam

Technical writer specializes in developer, Blogging and Online Journalism. I have been working in this field for the last 20 years.