简体   繁体   English

用户统计的数据库设计?

[英]Database design for user statistics?

I'm currently making an e-learning platform on where people can learn for their driving exam. 我目前正在建立一个在线学习平台,人们可以在该平台上学习驾驶考试。 The platform currently contains 5 exams (quizes), and until now, I just added a column for each of these exams on the user table so I could easily fetch them up later on using the user object. 该平台当前包含5个考试(测验),到目前为止,我只是在用户表上为这些考试中的每一个添加了一个列,以便以后在使用用户对象时可以轻松获取它们。 This is an example of my current user table: 这是我当前用户表的一个示例:

ID: 1
First_name: Johnny
Last_name: Dep
Exam_1: 60 (integer for % of exam completed, default 0)
Exam_2: 75 (integer for % of exam completed, default 0)
Exam_3: 35 (integer for % of exam completed, default 0)
Exam_4: 55 (integer for % of exam completed, default 0)
Exam_5: 90 (integer for % of exam completed, default 0)

However, I'm totally aware that this isn't a proper way to do it as it isn't dynamic at all. 但是,我完全意识到这不是正确的方法,因为它根本不是动态的。 If I ever have to add more exams, I'd have to manually extend the user table each time. 如果必须添加更多考试,则每次都必须手动扩展用户表。

So, what would be the a proper way to make this work dynamically? 那么,什么是使这项工作动态化的适当方法呢? I use a SQL database with Laravel for my development. 我在Laravel中使用SQL数据库进行开发。

One thing you could do would be to create a table for each exam. 您可以做的一件事就是为每次考试创建一个表格。 The columns would be user id's (foreign keys into the user table) and then a score. 列将是用户ID(用户表中的外键),然后是分数。 So when you create a new exam, you can populate it with id's of all the existing users and have their scores default to null. 因此,当您创建新考试时,可以使用所有现有用户的ID填充它,并将其分数默认为null。

Exam 1: 考试1:

Id score ID分数

1 Null 1空

2 60 2 60

3 90 3 90

User: 用户:

Id last first Id倒数第一

1 Dep Johnny 1德普·约翰尼

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM