在sql查询中使用foreach,面向对象数据库
以下是面向对象设置中的数据库方案。每个关系都成为对象的集合。学生是一个人,教员也是一个人。这些显示为标记为“isa”的有向边。所有其他有向边均显示参考属性。请注意,Course 中的 PreReq 属性是一组引用。
这是我需要编写的查询:对于每个分类,列出学生人数和平均 GPA。查询不能使用常量,例如“Freshman”。在输出中,每个元组应包含 Classification、NumOfStudents 和 AvgGPA。
我想如果我可以使用这些常量我就能够做到这一点。我认为某种 foreach 可以用于分类,但我不知道如何做到这一点。请注意,查询应该只使用基本的 mysql 语法编写。
The following is a scheme for a databse 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.
This is the query I need to write: For each classification, list the number of students and average GPA. The query can not use constants, such as "Freshman". In the output, each tuple should consist of Classification, NumOfStudents, and AvgGPA.
I think I would be able to do this if I could use the constants. I think some kind of foreach would work for the classification, but I can not figure out how to do this. Note that the query should just be written using basic mysql syntax.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个:
看起来应该有一些外键,因为可能需要连接 Person 表,但我在设计中没有看到它们。至少 group by 、 avg 和 count 函数应该让您走上正确的道路。
Try this:
It looks like there should be some foreign keys because the Person table might need to be joined, but I don't see them in the design. At least the group by and avg and count functions should get you going down the right path.