关系代数

发布于 2024-08-18 20:15:03 字数 924 浏览 9 评论 0原文

我想知道我是否可以获得一些关于我所做的关系代数的反馈,以及任何改进它的建议,如果你发现我的 SQL 有任何问题,你能否指出来。

SELECT CourseName
FROM Course
WHERE CourseNo = 6;

∏CourseName(σCourseNo=6(课程))

SELECT CU.UnitNo
FROM C.Course, CU CourseUnit
WHERE C.CourseName = CU.CourseNo
AND C.CourseName = 'Research';

∏UnitNo(CourseUnit(σC​​ourseName='Research'(课程)))

SELECT U.UnitName
FROM S Student, SU StudentUnit, U Unit
WHERE S.StudentNo = SU.StudentNo
AND SU.UnitNo = U.UnitNo
AND S.StudentName = 'John Perry';

∏UnitName(Unit(StudentUnit(σStudentName) ='John Perry'(学生))))

SELECT count(S.StudentNo) ResearchStudents
FROM C Course, S Student
WHERE C.CourseNo = S.CourseNo
AND C.CourseName = 'Research';

∏ResearchStudents((C)count(学生编号)(学生 (σCourseName='Research'(课程))))

I was wondering if I could get some feedback on the relational algebra I have done and any advice on improving it also if you see anything wrong with my SQL could you possibly point it out.

SELECT CourseName
FROM Course
WHERE CourseNo = 6;

∏CourseName(σCourseNo=6(Course))

SELECT CU.UnitNo
FROM C.Course, CU CourseUnit
WHERE C.CourseName = CU.CourseNo
AND C.CourseName = 'Research';

∏UnitNo(CourseUnit(σCourseName=’Research’(Course)))

SELECT U.UnitName
FROM S Student, SU StudentUnit, U Unit
WHERE S.StudentNo = SU.StudentNo
AND SU.UnitNo = U.UnitNo
AND S.StudentName = 'John Perry';

∏UnitName(Unit(StudentUnit(σStudentName=’John Perry’(Student))))

SELECT count(S.StudentNo) ResearchStudents
FROM C Course, S Student
WHERE C.CourseNo = S.CourseNo
AND C.CourseName = 'Research';

∏ResearchStudents((C)count(StudentNo)(Student (σCourseName=’Research’(Course))))

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

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

发布评论

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

评论(3

一腔孤↑勇 2024-08-25 20:15:03

from 子句有问题,我删除了 C.Course 之间的点

SELECT CU.UnitNo
FROM C Course, CU CourseUnit
WHERE C.CourseName = CU.CourseNo
AND C.CourseName = 'Research';

there is an issue in the from clause, I removed a dot between C.Course

SELECT CU.UnitNo
FROM C Course, CU CourseUnit
WHERE C.CourseName = CU.CourseNo
AND C.CourseName = 'Research';
不奢求什么 2024-08-25 20:15:03

除了 Pentium10 的注释之外,您还可以考虑使用 JOIN 子句,而不是在 WHERE 子句中指定联接。在我看来,它可以导致更容易理解的查询。所以

SELECT CU.UnitNo
FROM C Course, CU CourseUnit
WHERE C.CourseName = CU.CourseNo
AND C.CourseName = 'Research';

变成

SELECT CU.UnitNo
FROM C Course 
INNER JOIN CU CourseUnit
  ON C.CourseName = CU.CourseNo
WHERE C.CourseName = 'Research';

(旁注:表已被赋予别名,但未使用别名 - 如果我没记错的话,SQL Server会抱怨这一点并且不执行查询。不确定其他RDBMS)

On top of Pentium10's comment, you may consider using JOIN clauses as opposed to specifying the joins in the WHERE clause. In my opinion, it can lead to queries that are easier to follow. So

SELECT CU.UnitNo
FROM C Course, CU CourseUnit
WHERE C.CourseName = CU.CourseNo
AND C.CourseName = 'Research';

becomes

SELECT CU.UnitNo
FROM C Course 
INNER JOIN CU CourseUnit
  ON C.CourseName = CU.CourseNo
WHERE C.CourseName = 'Research';

(side note: the tables have been given aliases but the aliases aren't used - If my memory serves me correctly, SQL Server will complain about this and not execute the query. Not sure about other RDBMS)

格子衫的從容 2024-08-25 20:15:03

如果要使用您的语法,我想必须交换特殊字符。
(还记得 APL 键盘吗?)

在最后一个示例中,Course 和 C 之间的距离令人不安。

另外,您在第三个示例中的加入并不完整。

我认为 Query By Examples 或 Linq 是更有趣的选择。

If your syntax is going to be used, I guess the special characters must be exchanged.
(remember the APL keyboards?)

The distance between Course and C is disturbing, in your last example.

Also your Join in the 3rd example is not complete.

I think Query By Example or Linq are more interesting alternatives.

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