帮助将 SQL 查询转换为关系代数
我在将一些查询转换为关系代数时遇到一些困难。我有一本关于数据库设计的好书,这里有一章关于关系代数,但我似乎在创建正确的一章时遇到了一些麻烦:
我最困难的查询是这些:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
“这是关于关系代数的一章”
在哪里???这似乎并不能说明什么。
无论如何,您给出的例子都是具有代数视角的文献通常所说的“聚合”或“摘要”或类似的例子。
与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 !!!