我想在php
和mysql
中创建一个系统,用于计算学生成绩并显示结果,以便学校可以打印出成绩单。
当教师登录系统时,他/她只会看到他/她教的学生
我已经在数据库中有三个表(teachers
表,students
表,subjects
表。)
老师教授多个科目,老师教授不止一门课程。
我如何在数据库中实现它?
答案 0 :(得分:1)
这个问题并不适合StackOverflow,但我会尝试为您的表提供初稿:
TeacherId INT NOT NULL Primary key Autogenerated
FirstName VARCHAR(100)
LastName VARCHAR(100)
StudentId INT NOT NULL Primary key Autogenerated
FirstName VARCHAR(100)
LastName VARCHAR(100)
SubjectId INT NOT NULL Primary key Autogenerated
SubjectName VARCHAR(100)
TeacherXSubjectId INT NOT NULL Primary key Autogenerated
TeacherId INT NOT NULL FK -> Teacher
SubjectId INT NOT NULL FK -> Subject
应在(TeacherId
,SubjectId
)
ClassId INT NOT NULL Primary key Autogenerated
ClassName VARCHAR(100)
TeacherXClassId INT NOT NULL Primary key Autogenerated
TeacherId INT NOT NULL FK -> Teacher
ClassId INT NOT NULL FK -> Class
应在(TeacherId
,ClassId
)
ClassXStudentId INT NOT NULL Primary key Autogenerated
ClassId INT NOT NULL FK -> Class
StudentId INT NOT NULL FK -> Student
Grade INT -- type may depend on how the grade looks (numeric vs. A, B, ...)
第一个要求:看他/她教的学生
SELECT S.*
FROM Student S
INNER JOIN ClassXStudent CxS ON CxS.StudentId = S.StudentId
INNER JOIN TeacherXClass TxS ON TxS.ClassId = CxS.ClassId
WHERE T.TeacherId = <current teacher id>
尝试一下,然后回答更有针对性的问题:)。