我正在尝试根据来自两个不同表的另外两个变量来派生一个变量。我想知道一个学生在他们结束的队列学期(即他们离开大学的学期,无论是否毕业)的课程。我认为合并可能是错误的功能。这是我的代码:
select distinct s.colleagueId,st.term,
coalesce(EndProgram.EndProgram) EndProgram
from tbl_studentTerms st
inner join dbo.tbl_Terms t
on st.term = t.term
inner join
tbl_students s
on st.colleagueId = s.colleagueId
-- 结束队列计划
left join (
select st.activeProgram as EndProgram
from tbl_studentTerms st
inner join tbl_students s
on s.colleagueId=st.colleagueId
where st.term = s.endingCohort) EndProgram
on EndProgram.colleagueId = s.colleagueId