select sc.studentId , s.schoolName , c.className , st.recognizecode , st.trueName , uh.studyduration as timelength , case when ss.avgScore >0 then round(ss.avgScore) else 0 end as score , case when ss.howmuch >0 then ss.howmuch else 0 end as studyCount, uo.endTime , case when oa.status >0 then oa.status else 0 end as status, t.trueName as teacherName from sc inner join Classes c on sc.classesId = c.classesId inner join School s on s.schoolId = c.schoolId inner join Teacher t on c.teacherId = t.teacherId inner join Student st on sc.studentId = st.studentId left join UserHonor uh on sc.studentId = uh.uid left join ( select uid , avg(score) as avgScore, count(achivementid) as howmuch from Achivement where uid in ( select studentId from sc ) and achivetype in ('L','W') and pointcasetype in (3,4,5,6,7,8) and created > #{startTime} and created < #{endTime} group by uid ) ss on sc.studentId = ss.uid left join ( select uid , max( endTime ) as endTime from UserOwnLesson where uid in ( select studentId from sc ) group by uid ) uo on sc.studentId = uo.uid left join ( select uid , count(uid) as status from OrderInfo where uid in ( select studentId from sc ) and payway > 0 and ispayed = 1 and created > #{startTime} and created < #{endTime} group by uid ) oa on sc.studentId = oa.uid order by sc.studentId select a.teacherId , s.schoolName , t.loginNo , t.trueName , case when ta.assignmentCount >0 then ta.assignmentCount else 0 end as assignmentCount , case when cm.classMessageCount >0 then cm.classMessageCount else 0 end as classMessageCount, case when te.examCount >0 then te.examCount else 0 end as examCount , uo.endTime from tt as a inner join School as s on a.schoolId = s.schoolId inner join Teacher as t on a.teacherId = t.teacherId left join ( select teacherId , count( assignmentId ) as assignmentCount from Assignment where teacherId in ( select teacherId from tt ) #{startTime} ]]> and status != 0 group by teacherId ) as ta on a.teacherId = ta.teacherId left join ( select teacherId , count( classmessageId ) as classMessageCount from ClassMessage where teacherId in ( select teacherId from tt ) #{startTime} ]]> group by teacherId ) as cm on a.teacherId = cm.teacherId left join ( select teacherId , count( distinct e.examId ) as examCount from Classes c inner join ClassOwnExam coe on c.teacherId in ( select teacherId from tt ) and c.status = 1 and c.classesid = coe.classesId inner join Exam e on coe.examId = e.examId #{startTime} ]]> group by c.teacherId ) as te on a.teacherid = te.teacherid left join ( select uol.uid , max( uol.endTime ) as endTime from tt inner join UserOwnLesson uol on tt.teacherId = uol.uid group by uol.uid ) as uo on a.teacherId = uo.uid order by a.teacherId