MySQL + SQL · Lesson 116

School Database Case Study

About this Project

A complete School database case study with students, classes and fees — the running example used throughout this tutorial.

Database Schema

CREATE TABLE classes (class_id INT PRIMARY KEY, class_name VARCHAR(20));
CREATE TABLE students (roll_no INT PRIMARY KEY, name VARCHAR(50), class_id INT, marks INT,
  FOREIGN KEY(class_id) REFERENCES classes(class_id));
CREATE TABLE fees (fee_id INT PRIMARY KEY, roll_no INT, amount DECIMAL(8,2), paid_on DATE,
  FOREIGN KEY(roll_no) REFERENCES students(roll_no));

Useful Queries

-- topper of each class
SELECT class_id, name, marks FROM students s1
WHERE marks = (SELECT MAX(marks) FROM students s2 WHERE s2.class_id=s1.class_id);

-- total fee collected per class
SELECT c.class_name, SUM(f.amount) AS collected
FROM fees f JOIN students s ON f.roll_no=s.roll_no
           JOIN classes c ON s.class_id=c.class_id
GROUP BY c.class_name;

Summary

  • This project shows a real, exam-ready database design with working queries.
  • Create the tables, insert sample data, and run each query to learn by doing.
🔗

Share this topic with a friend

यह topic किसी दोस्त को भेजें

Found it useful? Send it to a classmate learning the same thing.

अच्छा लगा? जो दोस्त यही सीख रहा है, उसे भेज दीजिए।

WhatsApp