读书人

复杂的左联接查询

发布时间: 2012-07-27 11:03:00 作者: rapoo

复杂的左连接查询

一。查询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
?

?

?

?

读书人网 >其他数据库

热点推荐