关于学校数据库设计的问题
对于学校的年级模式来说,一个好的数据库设计应该是什么样的。
基本上,我有以下内容:
问题在于尝试获取平均成绩时。我无法得知前三个月所有科目的平均成绩。
关于评分系统的良好数据库设计有什么建议吗?
What would a good database design be for a school's grade schema.
Basically, I have the following:
The problem lies when trying to get the average of the grades. I can't get say the average of all grade in all subject in the first trimester.
Any suggestion on a good DB design for a grading system?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在数据库中包含一个包含平均成绩的字段是糟糕的数据库设计。此数据是多余的(因为您已经拥有在其他地方计算此值所需的所有数据),不应存储。一个主要的数据库设计规则是永远不要存储可以计算的内容。这导致您在更新一项时需要更新两项。在这种情况下,当您更新用于计算平均值的成绩时,您需要更新平均值表。
但是,您可能想要创建一个为您计算平均值的视图。视图基本上是一个由选择查询填充的表。要创建视图,首先创建一个选择查询,该查询返回您想要的平均值以及您想要用来查找该平均值的数据(最有可能是 IDSubject 或 IDStudent)。然后查找如何在数据库中创建视图,它应该能够从 Select 查询创建视图。
Having a field in the data base that contains the average grade is bad database design. This data is redundant (since you already have all the data you need to calculate this value elsewhere) and should not be stored. A major database design rule is never store what you can calculate. This results in you needed to update two things when you update one. In this case you would need to update the averages table when you update the grades that are used to calculate them.
However you might want to make a view that calculates the average for you. A view is basically a table that is populated by a select query. To go about creating a view first create a select query that returns the averages you want along with what ever data you want to use to look up this average (most likely IDSubject or IDStudent). Then look up how to create a view in your database, It should be able to create a view from a Select query.
在科目、成绩和分数之间添加班级表。
然后,您应该可以毫无问题地汇总和平均每个学期和每个年级的分数。
Add a class table between subject, grade and score.
You should then have no problem aggregating and averaging scores per trimester and per grade.