面向对象数据库的查询

发布于 2024-12-11 05:46:56 字数 389 浏览 0 评论 0原文

以下是面向对象设置中数据库的方案。每个关系都成为对象的集合。学生是一个人,教员也是一个人。这些显示为标记为“isa”的有向边。所有其他有向边均显示参考属性。请注意,Course 中的 PreReq 属性是一组引用。

在此处输入图像描述

这是我不知道如何编写的查询:

按 StudentID 重新组织注册集合。对于每个学生,检索学生的 ID 和成绩。 Grade 应该是由 CourseCodeLetterGrade 属性组成的关系。

通过重新组织,我很确定这只是意味着按该顺序检索信息,而不是对数据库进行任何更新。

The following is a scheme for a database in an object-oriented setting. Every relation becomes a collection of objects. A Student is a person and a Faculty is also a person. These are shown as directed edges labeled "isa". All other directed edges show reference attributes. Note that PreReq attribute in Course is a set of references.

enter image description here

Here is the query I can't figure out how to write:

Reorganize Enrollment collection by StudentID. For each student, retrieve the student's id and a Grade. The Grade should be a relation consisting of CourseCode and LetterGrade attributes.

By re-organize, I am pretty sure it just means retrieve the info in that order, and NOT do any updates to the database.

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

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

发布评论

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

评论(1

青春如此纠结 2024-12-18 05:46:56

因为并非所有字段都被正确引用,并且说明有点……好吧,缺乏,我将做出一些假设。即:

  1. 学生表有一个名为“StudentID”的字段,它与 Person 表中的 ID 字段是 1 对 1 的关系。

  2. “重新组织”的意思是“选择”......奇怪的措辞。

  3. 除了 Person 表之外,所有其他 ID 都遵循正常的命名约定。意思是,Id。例如,学生表中的主 ID 是 StudentID

  4. 问题中的“LetterGrade”实际上指的是注册表中的“Grade”字段。

  5. 所有以“Info”结尾的字段都是以“Id”结尾的等效字段的外键。例如: Enrollment.StudentInfo 映射到 Student.StudentId

类似的东西

SELECT S.StudentID, E.Grade, C.CourseCode
FROM Student S
  INNER JOIN Enrollment E on (E.StudentInfo = S.StudentId)
  INNER JOIN Offering O on (O.OfferingId = E.OfferingInfo)
  INNER JOIN Course C on (C.CourseId = O.CourseInfo)
ORDER BY S.StudentId

Because not all of the fields are properly referenced and the instructions are a bit... well, lacking, I'm going to make a few assumptions. Namely:

  1. The student table has a field called "StudentID" which is a 1 to 1 relationship with the ID field in the Person table.

  2. "Reorganize" means "select".. Odd phrasing that.

  3. Other than the Person table, all other IDs follow normal naming conventions. Meaning, <TableName>Id. For example, the primary ID in the student table is StudentID

  4. "LetterGrade" in the question actually refers to the "Grade" field in the enrollment table.

  5. All fields ending in the word "Info" are foreign keys to the equivalent field ending in "Id". For example: Enrollment.StudentInfo maps to Student.StudentId

Something along the lines of

SELECT S.StudentID, E.Grade, C.CourseCode
FROM Student S
  INNER JOIN Enrollment E on (E.StudentInfo = S.StudentId)
  INNER JOIN Offering O on (O.OfferingId = E.OfferingInfo)
  INNER JOIN Course C on (C.CourseId = O.CourseInfo)
ORDER BY S.StudentId
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文