需要数据库设计方面的帮助

发布于 2024-10-23 12:24:11 字数 486 浏览 5 评论 0原文

我目前不知道如何设计这张桌子,所以我真的很想得到一些建议。说明如下:

表将保存3个考试结果。

  1. 考试 A:8 门必修科目,无限选修科目。
  2. 考试 B:6 门必修科目,无限选修科目。
  3. 考试 C:1 门必修科目,4 门选修科目。

要记住的功能:

  1. 每个科目的结果都需要可搜索(例如:在考试 A 中查找数学 A)
  2. 基本总计算(例如:计算考试 A 的数学中有多少个 A)

只需插入数据我就能想到然而,当将这些功能混合在一起时,它就行不通了。

我的最后一招是使用一张表:studentid、exam、subjectcode、result。这将像可搜索和可计算一样工作,但从长远来看,我有一种非常混乱和巨大的数据库的感觉。

我目前的设计(由我的朋友提供): 每个主题及其结果都有自己的领域。它有效,但很难扩展(添加更多主题)。

有什么建议吗?

I am currently out of idea how to design this table so I would really like some suggestions. Description as follows:

Table will hold 3 exam result.

  1. Exam A: 8 mandatory subject with infinite optional subject.
  2. Exam B: 6 mandatory subject with infinite optional subject.
  3. Exam C: 1 mandatory subject with 4 optional subject.

Feature to keep in mind:

  1. Each subject's result need to be searchable (eg: Find A for Math in Exam A)
  2. Basic total calculation (eg: calculate how many As in Math for Exam A)

Just inserting data I would be able to think of something however when putting the features into the mix, it just won't work.

My last resort is having a single table with: studentid, exam, subjectcode, result. This will work as in searchable and calculable however I have a feeling of a very messy and huge database in the long run.

My current design (given by my friend):
Each subject and its result have its own field. It works but very hard to expand (add more subjects).

Any recommendations?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

驱逐舰岛风号 2024-10-30 12:24:11

可能的表结构(省略列定义):

Exam
---------
Exam_ID
Exam_name 
number_of_req_subjects
number_of_opt_subjects  <---- -1 could be infinite

Subject
-----------
Subject_id
subject_name

exam_subject
------------
exam_subject_id
exam_id
subject_id
required

exam_result
------------
exam_result_id
exam_subject_id
result  

获取考试 A 中数学的 A 数:(

SELECT count(exam_result_id)
FROM exam_result er, exam_subject es, subject s, exam e
WHERE er.exam_subject_id = es.exam_subject_id
AND es.subject_id = s.subject_id
AND es.exam_id = e.exam_id
AND e.exam_name = 'A'
AND s.subject_name = 'MATH'

我知道使用联接比联接不同表的位置更好,但我有点懒)。

主题结果可搜索...我们没有足够的信息。事实上,我的答案可能完全不对劲,但已经是我认为根据目前给定信息所能得到的最接近的答案了。使某些内容可搜索只需创建一个足够有用的 select 语句即可。

Possible table structure (leaving out column definitions):

Exam
---------
Exam_ID
Exam_name 
number_of_req_subjects
number_of_opt_subjects  <---- -1 could be infinite

Subject
-----------
Subject_id
subject_name

exam_subject
------------
exam_subject_id
exam_id
subject_id
required

exam_result
------------
exam_result_id
exam_subject_id
result  

To get the number of A's for Math in Exam A:

SELECT count(exam_result_id)
FROM exam_result er, exam_subject es, subject s, exam e
WHERE er.exam_subject_id = es.exam_subject_id
AND es.subject_id = s.subject_id
AND es.exam_id = e.exam_id
AND e.exam_name = 'A'
AND s.subject_name = 'MATH'

(I know using joins would be better than where to join the different tables, but I'm being a bit lazy).

The subjects result being searchable...we don't have enough information. In fact, my answer may be completely off, but is as close as I think I can get it with the given information at the moment. Making something searchable is just a matter of creating a sufficiently useful select statment.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文