在sql查询中使用foreach,面向对象数据库

发布于 2024-12-10 19:20:32 字数 389 浏览 0 评论 0原文

以下是面向对象设置中的数据库方案。每个关系都成为对象的集合。学生是一个人,教员也是一个人。这些显示为标记为“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.

enter image description here

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 技术交流群。

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

发布评论

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

评论(1

恋你朝朝暮暮 2024-12-17 19:20:32

试试这个:

SELECT Classification, COUNT(*), AVG(GPA) 
FROM Student 
GROUP BY Classification

看起来应该有一些外键,因为可能需要连接 Person 表,但我在设计中没有看到它们。至少 group by 、 avg 和 count 函数应该让您走上正确的道路。

Try this:

SELECT Classification, COUNT(*), AVG(GPA) 
FROM Student 
GROUP BY Classification

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.

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