select sc.studentId , s.schoolName , c.className , st.recognizecode , st.trueName , case when uc.timelength>0 then uc.timelength else 0 end 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, t.trueName as teacherName , uc.loginCount from sc inner join UnivClasses c on sc.classesId = c.classesId inner join university s on s.schoolId = c.schoolId inner join UnivTeacher t on c.teacherId = t.teacherId inner join UnivStudent st on sc.studentId = st.studentId left join UnivUserHonor uh on sc.studentId = uh.uid left join ( select uid , avg(score) as avgScore, count(achivementid) as howmuch from UnivAchivement where uid in ( select studentId from sc ) and achivetype in ('L','W') and pointcasetype in (3,5,6,7,8) and created > #{startTime} and created < #{endTime} group by uid ) ss on sc.studentId = ss.uid left join ( select studentId ,sum(ucl.timelength) as timelength, count( distinct ucl.connectlogid ) as loginCount from sc inner join UnivConnectLog ucl on sc.studentId = ucl.uid #{startTime} ]]> group by sc.studentId ) as uc on sc.studentId = uc.studentId order by sc.studentId select sc.studentId , s.schoolName , c.className , st.recognizecode , st.trueName , case when uc.timelength>0 then uc.timelength else 0 end 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, t.trueName as teacherName , case when uc.loginCount >0 then uc.loginCount else 0 end as loginCount from sc inner join UnivClasses c on sc.classesId = c.classesId and classtype=1 inner join university s on s.schoolId = c.schoolId inner join UnivTeacher t on c.teacherId = t.teacherId inner join UnivStudent st on sc.studentId = st.studentId left join UnivUserHonor uh on sc.studentId = uh.uid left join ( select uid , avg(score) as avgScore, count(achivementid) as howmuch from UnivAchivement where uid in ( select studentId from sc ) and achivetype in ('L','W') and pointcasetype in (3,5,6,7,8) and created > #{startTime} and created < #{endTime} group by uid ) ss on sc.studentId = ss.uid left join ( select studentId ,sum(ucl.timelength) as timelength, count( distinct ucl.connectlogid ) as loginCount from sc inner join UnivConnectLog ucl on sc.studentId = ucl.uid #{startTime} ]]> group by sc.studentId ) as uc on sc.studentId = uc.studentId order by loginCount desc order by studyCount desc order by timelength desc LIMIT #{pageSize} OFFSET #{offset} 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 , case when uc.loginCount >0 then uc.loginCount else 0 end as loginCount from tt as a inner join University as s on a.schoolId = s.schoolId inner join UnivTeacher as t on a.teacherId = t.teacherId left join ( select teacherId , count( assignmentId ) as assignmentCount from UnivAssignment where teacherId in ( select teacherId from tt ) #{startTime} ]]> group by teacherId ) as ta on a.teacherId = ta.teacherId left join ( select teacherId , count( classmessageId ) as classMessageCount from UnivClassMessage where teacherId in ( select teacherId from tt ) #{startTime} ]]> group by teacherId ) as cm on a.teacherId = cm.teacherId left join ( select c.teacherId , count( distinct e.examId ) as examCount from UnivClasses c inner join UnivClassOwnExam coe on c.teacherId in ( select teacherId from tt ) and c.status = 1 and c.classesid = coe.classesId inner join UnivExam e on coe.examId = e.examId #{startTime} ]]> group by c.teacherId ) as te on a.teacherid = te.teacherid left join ( select teacherId , count( ucl.connectlogid ) as loginCount from tt inner join UnivConnectLog ucl on tt.teacherId = ucl.uid #{startTime} ]]> group by tt.teacherId ) as uc on a.teacherid = uc.teacherid order by a.teacherId