帮助将 SQL 查询转换为关系代数

发布于 2024-08-25 03:02:37 字数 675 浏览 13 评论 0原文

我在将一些查询转换为关系代数时遇到一些困难。我有一本关于数据库设计的好书,这里有一章关于关系代数,但我似乎在创建正确的一章时遇到了一些麻烦:

我最困难的查询是这些:

SELECT COUNT( cs.student_id ) AS counter
FROM course c, course_student cs
WHERE c.id = cs.course_id
AND c.course_name = 'Introduction to Database Design'

SELECT COUNT( cs.student_id ) 
FROM Course c
INNER JOIN course_student cs ON c.id = cs.course_id
WHERE c.course_name = 'Introduction to Database Design'

SELECT COUNT( * ) 
FROM student
JOIN grade ON student.f_name = "Andreas"
AND student.l_name = "Pedersen"
AND student.id = grade.student_id

知道符号可能有点很难粘贴到 HTML 论坛中,但也许只是使用一些常用名称或希腊名称。

提前致谢 梅斯蒂卡

I'm having some difficulties with translating some queries to Relational Algebra. I've a great book about Database Design and here is a chapter about Relational Algebra but I still seem to have some trouble creating the right one:

Thoes queries I've most difficuelt with is these:

SELECT COUNT( cs.student_id ) AS counter
FROM course c, course_student cs
WHERE c.id = cs.course_id
AND c.course_name = 'Introduction to Database Design'

SELECT COUNT( cs.student_id ) 
FROM Course c
INNER JOIN course_student cs ON c.id = cs.course_id
WHERE c.course_name = 'Introduction to Database Design'

and

SELECT COUNT( * ) 
FROM student
JOIN grade ON student.f_name = "Andreas"
AND student.l_name = "Pedersen"
AND student.id = grade.student_id

I know the notation can be a bit hard to paste into HTML forum, but maybe just use some common name or the Greek name.

Thanks in advance
Mestika

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

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

发布评论

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

评论(1

小兔几 2024-09-01 03:02:37

“这是关于关系代数的一章”

在哪里???这似乎并不能说明什么。

无论如何,您给出的例子都是具有代数视角的文献通常所说的“聚合”或“摘要”或类似的例子。

与JOIN、PROJECT等“基本”算子相比,对于如何处理此类“聚合算子”的共识相对较少。请记住,不存在“关系代数”这样的东西,并且不同的实现可以完全自由地选择向用户提供的代数运算符集合!

"and here is a chapter about Relational Algebra"

Where ??? This doesn't seem to point to anything.

At any rate, the examples you give are examples of what the literature-with-an-algebraic-perspective usually calls "aggregations", or "summaries", or some such.

In contrast with the "basic" operators such as JOIN, PROJECT, etc., the consensus on how to deal with such "aggregate operators" is relatively small. Keep in mind that there is no such thing as "the" relational algebra, and that different implementations are completely free to choose which set of algebraic operators they make available to their users !!!

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