课程 - 学生 - 老师 之间的关系(四表)
SQL语句
(A - B) - (C -D)
select
cid,cname,ctype,chours,
tid,tname,tsex,tphone,
sid,sname,ssex,spwd,sphone,sgrade,sphoto
from
(
select
c.id cid,
c.name cname,
c.type ctype,
c.hours chours,
t.id tid,
t.name tname,
t.sex tsex,
t.phone tphone
from
course c
left JOIN
teacher t
on c.tid=t.id
) t1
left join
(
select
s.id sid,
s.name sname,
s.sex ssex,
s.pwd spwd,
s.phone sphone,
s.grade sgrade,
s.photo sphoto,
sc.cid sccid
from
student_course sc
left join
student s
on sc.sid=s.id
) t2
on t1.cid=t2.sccid
where t1.cid=#{id}