复杂的左连接查询
一。查询A表的所有字段,还要查询和A表关联的B表的C字段的个数,条件是A.Fnum=B.Cnum

在上例中,学习人数和完成人数之前的字段都是A表的字段,学习人数和完成人数需要关联查询B表。
?
select t.fid, t.fcourse_code,t.fcourse_name, t.funit,t.flevel, tcou.tc, tstu.lcc, ware.cs from course_info t left join (select count(1) as tc,fcourse_id from teachplan_course where fcourse_id is not null group by fcourse_id) tcou on tcou.fcourse_id=t.fid left join (select fid, fcourse_id from Teach_Arrangement where fcourse_id is not null group by fcourse_id,fid) tarr on tarr.fcourse_id=t.fid left join (select count(1) lcc,FTEACH_ARRANGEMENT_ID from TEACHPLAN_STUDENT_CHOOSE where FTEACH_ARRANGEMENT_ID is not null group by FTEACH_ARRANGEMENT_ID) tstu on tstu.FTEACH_ARRANGEMENT_ID=tarr.fid left join (select count(1) as cs,FCOURSE_ID from courseware where FCOURSE_ID is not null group by FCOURSE_ID) ware on ware.FCOURSE_ID=t.fid where 1=1?
?
?
?