MySQL:列出在 99F 学期教授 CS160 部分和 CS340 部分的教师(姓名)
架构如下:
Student(Snum, Sname)
Course(Cnum, Cname)
Professor(Pnum,Pname, Dept, Office)
Class(Cnum, Term, Section, Instructor)
我如何加入下面的两个选择以获得同时教授 CS160 和 CS340 的讲师?
SELECT DISTINCT Instructor FROM class
WHERE Term = "99F" AND Cnum = "CS160"
SELECT DISTINCT Instructor FROM class
WHERE Term = "99F" AND Cnum = "CS340"
谢谢!
The schema is as follows:
Student(Snum, Sname)
Course(Cnum, Cname)
Professor(Pnum,Pname, Dept, Office)
Class(Cnum, Term, Section, Instructor)
How can I join the two selects below to get Instructors who taught both CS160 and CS340?
SELECT DISTINCT Instructor FROM class
WHERE Term = "99F" AND Cnum = "CS160"
SELECT DISTINCT Instructor FROM class
WHERE Term = "99F" AND Cnum = "CS340"
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于MySql没有
intersect
,所以你必须进行自连接;类似于:编辑:与相交,只需将
intersect
说明符放在示例中的两个查询之间(并且可以省略“distinct”;“intersect”仅返回不同的值):intersect
是 SQL 标准的一部分,但 MySql 没有实现它。确实具有相交的 SQL 实现包括 Oracle 和 Postgres。另请参阅 mySQL 与标准 SQL
Since MySql doesn't have
intersect
, you have to do a self-join; something like:Edit: with intersect, you just put the
intersect
specifier between the 2 queries you had in your example (and you can omit the "distinct"; "intersect" returns only distinct values):intersect
is part of the SQL standard, but MySql doesn't implement it. SQL implementations that do haveintersect
include Oracle and Postgres.See also mySQL versus Standard SQL