简体   繁体   中英

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. 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.

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. 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.

Exam 1:

Id score

1 Null

2 60

3 90

User:

Id last first

1 Dep Johnny

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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