我有多个表但是对于这个查询只需要两个表,即Faculty和CourseSection。 我尝试过以下但是失败了。如果有人可以提供帮助。
Select faculty.firstname,faculty.lastname,CourseSection.facid,courseID
from CourseSection,faculty
where CourseSection.facid in(
Select CourseSection.CourseID
from CourseSection
where CourseSection.facid =Faculty.facid and firstname='John' AND lastname='Cullen')
答案 0 :(得分:2)
您应该在表格之间使用左连接(假设您的表格与CourseSection.facid = faculty.facid相关)
Select
faculty.firstname
,faculty.lastname
, CourseSection.facid
, CourseSection.courseID
from CourseSection
LEFT JOIN faculty on CourseSection.facid = faculty.facid
where CourseSection.facid in (
Select CourseSection.CourseID
from CourseSection
where CourseSection.facid =Faculty.facid
and firstname='John' AND lastname='Cullen')
答案 1 :(得分:0)
您需要Faculty
CourseSection
FacID
加入CourseSection
一次,找到'John Cullen'教授的课程,再次加入CourseID
Faculty
查找所选课程的所有教师(我想不包括“John Allen”),最后再次使用select f2.facid, f2.firstname,f2.lastname, c2.courseID
from Faculty f join CourseSection c on f.facid = c.facid
join CourseSection c2 on c.CourseID = c2.CourseID
join Faculty f2 on c2.facid = f2.facid and f.facid <> f2.facid
where f.FirstName = 'John' and f.LastName = 'Cullen';
加入教师的数据(点击 here 演示):
import {GoogleChart} from '../directives/angular2-google-chart.directive';
@NgModule({
imports: [ ],
declarations: [GoogleChart]
})