关系代数
我想知道我是否可以获得一些关于我所做的关系代数的反馈,以及任何改进它的建议,如果你发现我的 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(σCourseName='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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
from 子句有问题,我删除了 C.Course 之间的点
there is an issue in the from clause, I removed a dot between C.Course
除了 Pentium10 的注释之外,您还可以考虑使用
JOIN
子句,而不是在WHERE
子句中指定联接。在我看来,它可以导致更容易理解的查询。所以变成
(旁注:表已被赋予别名,但未使用别名 - 如果我没记错的话,SQL Server会抱怨这一点并且不执行查询。不确定其他RDBMS)
On top of Pentium10's comment, you may consider using
JOIN
clauses as opposed to specifying the joins in theWHERE
clause. In my opinion, it can lead to queries that are easier to follow. Sobecomes
(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)
如果要使用您的语法,我想必须交换特殊字符。
(还记得 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.