spokenServer/out/production/pcserver/sqlmap/UnivStudyStatistics.xml
2026-03-10 14:30:24 +08:00

715 lines
29 KiB
XML

<?xml version="1.0" encoding="UTF-8"?><!--Converted at: Wed Jul 11 17:43:20 CST 2018-->
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="UnivStudyStatistics">
<select id="UnivStudyStatByClass" parameterType="java.util.Map" resultType="StudyStatInfo">
with temp as( select a.assignmentid,a.starttime,a.endtime,c.unitid,c.lessonid,a.assigntype from univassignment a
inner join univassigntoclass b
on a.assignmentid=b.assignmentid and b.classesid=#{classesId}
and a.created&gt; #{startTime} and a.created &lt;=#{endTime}
inner join univassigndetail c on a.assignmentid=c.assignmentid ),
temp1 as(
select assignmentid,count(lessonid) lessoncount from temp where assigntype='L' group by assignmentid),
temp2 as(
select studentid ,c.assignmentid,count(distinct b.objectid) completecount from univstudentownclass a inner join univachivement b on a.studentid=b.uid inner join
temp c on b.objectid=c.lessonid and c.assigntype='L' and b.created&gt;c.starttime and b.created&lt;c.endtime
group by studentid,c.assignmentid),
temp3 as(select b.studentid ,count(case when a.lessoncount=b.completecount then 1 else null end ) finishcount from temp1 a inner join temp2 b on a.assignmentid=b.assignmentid
group by b.studentid),
temp4 as(select a.assignmentid,a.starttime,a.endtime,b.wordsid from temp a inner join words b on a.unitid=b.lessonid and a.assigntype='W'),
temp5 as(select assignmentid,count(wordsid) lessoncount from temp4 group by assignmentid),
temp6 as(select studentid ,c.assignmentid,count(distinct b.wordsid) completecount from univstudentownclass a inner join univwordachive b on a.studentid=b.uid inner join
temp4 c on b.wordsid=c.wordsid and b.created&gt;c.starttime and b.created&lt;c.endtime
group by studentid,c.assignmentid ),
temp7 as (select b.studentid ,count(case when a.lessoncount=b.completecount then 1 else null end ) finishcount from temp5 a inner join temp6 b on a.assignmentid=b.assignmentid
group by b.studentid)
select b.studentId as uid , b.recognizeCode , b.trueName , b.nickname ,
c.totalTime , c.totalNum , d.avgScore , d.totalLesson, e.totalAssign
from UnivStudentOwnClass a
inner join UnivStudent b
on a.classesId = #{classesId} and a.studentId = b.studentId and a.status = 1 and b.status=1
left join (select m.studentId , sum( timeLength ) as totalTime , count(*) as totalNum
from UnivStudentOwnClass m
inner join UnivConnectLog n
on m.classesId = #{classesId} and m.studentId = n.uid
where n.created &gt; #{startTime} and n.endTime &lt;= #{endTime}
group by m.studentId ) c
on a.studentId = c.studentId
left join (select p.studentId , avg( q.score ) as avgScore ,
count( objectId ) as totalLesson
from UnivStudentOwnClass p
inner join UnivAchivement q
on p.classesId = #{classesId} and p.studentId = q.uid
and q.pointCaseType in (3, 5 , 6 , 7 , 8 )
and q.achiveType in ( 'L' , 'W' )
where q.created &gt; #{startTime} and q.created &lt;= #{endTime}
group by p.studentId ) d
on a.studentId = d.studentId
left join (select studentid,sum(finishcount ) totalAssign from (select * from temp3 union all select * from temp7 ) as a group by studentid) e
on a.studentId = e.studentId
order by a.studentId
limit #{pageSize} offset #{offset}
</select>
<select id="UnivstudentStatCurve" parameterType="java.util.Map" resultType="StudyStatCurve">
SELECT extract( year from a.created ) as myYear ,
extract( month from a.created ) as myMonth,
max( a.score ) as maxScore , avg( a.score ) as avgScore
FROM UnivAchivement a
WHERE a.uid = #{uid}
AND a.created &gt; #{startTime} and a.created &lt;= #{endTime}
AND a.achiveType in ('L','W')
AND a.pointCaseType in (3, 5, 6 , 7 , 8 )
GROUP BY extract( year from a.created ) ,
extract( month from a.created )
ORDER BY myYear desc , myMonth desc
</select>
<select id="UnivclassesStatCurve" parameterType="java.util.Map" resultType="StudyStatCurve">
SELECT extract( year from b.created ) as myYear ,
extract( month from b.created ) as myMonth,
max( b.score ) as maxScore , avg( b.score ) as avgScore
FROM UnivStudentOwnClass a
INNER JOIN UnivAchivement b
ON a.classesId = #{classesId} and a.status = 1
AND a.studentId = b.uid
WHERE b.created &gt; #{startTime} and b.created &lt;= #{endTime}
AND b.achiveType in ('L','W')
AND b.pointCaseType in (3, 5, 6 , 7 , 8 )
GROUP BY extract( year from b.created ) ,
extract( month from b.created )
ORDER BY myYear , myMonth
</select>
<select id="UnivsingleArchStat" parameterType="java.util.Map" resultType="SingleArchStat">
SELECT a.objectId as lessonId ,a.pointCaseType , a.score as score ,
a.created as lastTime
FROM univAchivement a
WHERE a.uid = #{uid} AND a.achiveType in ('L','W')
AND a.created &gt; #{startTime} AND a.created &lt; #{endTime}
<if test="pointCaseType != null">AND
pointCaseType = #{pointCaseType}
</if>
AND pointCaseType in (3, 5, 6 , 7 , 8 )
ORDER BY lastTime desc
<if test="pageSize!=null">
LIMIT #{pageSize}
</if>
<if test="offset!=null">
OFFSET #{offset}
</if>
</select>
<select id="UnivsingleArchStatCount" parameterType="java.util.Map" resultType="Integer">
SELECT count(*)
FROM univAchivement a
WHERE a.uid = #{uid} AND a.achiveType in ('L','W')
AND a.created &gt; #{startTime} AND a.created &lt; #{endTime}
<if test="pointCaseType != null">AND
pointCaseType = #{pointCaseType}
</if>
AND pointCaseType in (3, 5, 6 , 7 , 8 )
</select>
<select id="UnivsingleArchStatAllCase" parameterType="java.util.Map" resultType="SingleArchStat">
SELECT a.objectId as lessonId , pointCaseType , a.score as score ,
a.created as lastTime
FROM univAchivement a
WHERE a.uid = #{uid} AND a.achiveType in ('L','W')
AND a.created &gt; #{startTime} AND a.created &lt; #{endTime}
AND pointCaseType in (3, 5, 6 , 7 , 8 )
ORDER BY lastTime desc
<if test="pageSize!=null">
LIMIT #{pageSize}
</if>
<if test="offset!=null">
OFFSET #{offset}
</if>
</select>
<select id="UnivsingleArchStatAllCaseCount" parameterType="java.util.Map" resultType="Integer">
SELECT count(*)
FROM univAchivement a
WHERE a.uid = #{uid} AND a.achiveType in ('L','W')
AND a.created &gt; #{startTime} AND a.created &lt; #{endTime}
AND pointCaseType in (3, 5, 6 , 7 , 8 )
</select>
<select id="UnivclassArchStat" parameterType="java.util.Map" resultType="SingleArchStat">
SELECT a.objectId as lessonId ,a.pointCaseType , a.score as score ,
a.created as lastTime
FROM univAchivement a
WHERE a.uid in ( select distinct studentId
from Univstudentownclass
where classesid= #{classesId} and status = 1)
AND a.achiveType in ('L','W')
AND a.created &gt; #{startTime} AND a.created &lt; #{endTime}
<if test="pointCaseType != null">AND
pointCaseType = #{pointCaseType}
</if>
AND pointCaseType in (3, 5, 6 , 7 , 8 )
ORDER BY lastTime desc
<if test="pageSize!=null">
LIMIT #{pageSize}
</if>
<if test="offset!=null">
OFFSET #{offset}
</if>
</select>
<select id="UnivclassArchStatCount" parameterType="java.util.Map" resultType="Integer">
SELECT count(*)
FROM univAchivement a
WHERE a.uid in ( select distinct studentId
from Univstudentownclass
where classesid= #{classesId} and status = 1)
AND a.achiveType in ('L','W')
AND a.created &gt; #{startTime} AND a.created &lt; #{endTime}
<if test="pointCaseType != null">AND
pointCaseType = #{pointCaseType}
</if>
AND pointCaseType in (3, 5, 6 , 7 , 8 )
</select>
<select id="UnivclassArchStatAllCase" parameterType="java.util.Map" resultType="SingleArchStat">
SELECT a.objectId as lessonId , pointCaseType , a.score as score ,
a.created as lastTime
FROM univAchivement a
WHERE a.uid in ( select distinct studentId
from studentownclass
where classesid= #{classesId} and status = 1)
AND a.achiveType in ('L','W')
AND a.created &gt; #{startTime} AND a.created &lt; #{endTime}
AND pointCaseType in (3, 5, 6 , 7 , 8 )
ORDER BY lastTime desc
<if test="pageSize!=null">
LIMIT #{pageSize}
</if>
<if test="offset!=null">
OFFSET #{offset}
</if>
</select>
<select id="UnivclassArchStatAllCaseCount" parameterType="java.util.Map" resultType="Integer">
SELECT count(*)
FROM univAchivement a
WHERE a.uid in ( select distinct studentId
from studentownclass
where classesid= #{classesId} and status = 1)
AND a.achiveType in ('L','W')
AND a.created &gt; #{startTime} AND a.created &lt; #{endTime}
AND pointCaseType in (3, 5, 6 , 7 , 8 )
</select>
<select id="UnivMaxclassArchStat" parameterType="java.util.Map" resultType="SingleArchStat">
SELECT a.objectId as lessonId ,a.pointCaseType , max( a.score ) as score ,
max( a.created ) as lastTime
FROM univAchivement a
WHERE a.uid in ( select distinct studentId
from Univstudentownclass
where classesid= #{classesId} and status = 1)
AND a.achiveType in ('L','W')
AND a.created &gt; #{startTime} AND a.created &lt; #{endTime}
<if test="pointCaseType != null">AND
pointCaseType = #{pointCaseType}
</if>
AND pointCaseType in (3, 5, 6 , 7 , 8 )
GROUP BY a.objectId , a.pointCaseType
ORDER BY lastTime desc
<if test="pageSize!=null">
LIMIT #{pageSize}
</if>
<if test="offset!=null">
OFFSET #{offset}
</if>
</select>
<select id="UnivMaxclassArchStatCount" parameterType="java.util.Map" resultType="Integer">
SELECT count(distinct (a.objectId, a.pointCaseType))
FROM univAchivement a
WHERE a.uid in ( select distinct studentId
from Univstudentownclass
where classesid= #{classesId} and status = 1 )
AND a.achiveType in ('L','W')
AND a.created &gt; #{startTime} AND a.created &lt; #{endTime}
<if test="pointCaseType != null">AND
pointCaseType = #{pointCaseType}
</if>
AND pointCaseType in (3, 5, 6 , 7 , 8 )
</select>
<select id="UnivMaxclassArchStatAllCase" parameterType="java.util.Map" resultType="SingleArchStat">
SELECT a.objectId as lessonId , pointCaseType , max( a.score ) as score ,
max( a.created ) as lastTime
FROM univAchivement a
WHERE a.uid in ( select distinct studentId
from Univstudentownclass
where classesid= #{classesId} and status = 1)
AND a.achiveType in ('L','W')
AND a.created &gt; #{startTime} AND a.created &lt; #{endTime}
AND pointCaseType in (3, 5, 6 , 7 , 8 )
GROUP BY a.objectId , pointCaseType
ORDER BY lastTime desc
<if test="pageSize!=null">
LIMIT #{pageSize}
</if>
<if test="offset!=null">
OFFSET #{offset}
</if>
</select>
<select id="UnivMaxclassArchStatAllCaseCount" parameterType="java.util.Map" resultType="Integer">
SELECT count(distinct (a.objectId))
FROM univAchivement a
WHERE a.uid in ( select distinct studentId
from Univstudentownclass
where classesid= #{classesId} and status = 1)
AND a.achiveType in ('L','W')
AND a.created &gt; #{startTime} AND a.created &lt; #{endTime}
AND pointCaseType in (3, 5, 6 , 7 , 8 )
</select>
<select id="UnivMaxsingleArchStat" parameterType="java.util.Map" resultType="SingleArchStat">
SELECT a.objectId as lessonId ,a.pointCaseType , max( a.score ) as score ,
max( a.created ) as lastTime
FROM univAchivement a
WHERE a.uid = #{uid} AND a.achiveType in ('L','W')
AND a.created &gt; #{startTime} AND a.created &lt; #{endTime}
<if test="pointCaseType != null">AND
pointCaseType = #{pointCaseType}
</if>
AND pointCaseType in (3, 5, 6 , 7 , 8 )
GROUP BY a.objectId , a.pointCaseType
ORDER BY lastTime desc
<if test="pageSize!=null">
LIMIT #{pageSize}
</if>
<if test="offset!=null">
OFFSET #{offset}
</if>
</select>
<select id="UnivMaxsingleArchStatCount" parameterType="java.util.Map" resultType="Integer">
SELECT count(distinct (a.objectId, a.pointCaseType))
FROM univAchivement a
WHERE a.uid = #{uid} AND a.achiveType in ('L','W')
AND a.created &gt; #{startTime} AND a.created &lt; #{endTime}
<if test="pointCaseType != null">AND
pointCaseType = #{pointCaseType}
</if>
AND pointCaseType in (3, 5, 6 , 7 , 8 )
</select>
<select id="UnivMaxsingleArchStatAllCase" parameterType="java.util.Map" resultType="SingleArchStat">
SELECT a.objectId as lessonId , pointCaseType , max( a.score ) as score ,
max( a.created ) as lastTime
FROM univAchivement a
WHERE a.uid = #{uid} AND a.achiveType in ('L','W')
AND a.created &gt; #{startTime} AND a.created &lt; #{endTime}
AND pointCaseType in (3, 5, 6 , 7 , 8 )
GROUP BY a.objectId , pointCaseType
ORDER BY lastTime desc
<if test="pageSize!=null">
LIMIT #{pageSize}
</if>
<if test="offset!=null">
OFFSET #{offset}
</if>
</select>
<select id="UnivMaxsingleArchStatAllCaseCount" parameterType="java.util.Map" resultType="Integer">
SELECT count(distinct a.objectId )
FROM univAchivement a
WHERE a.uid = #{uid} AND a.achiveType in ('L','W')
AND a.created &gt; #{startTime} AND a.created &lt; #{endTime}
AND pointCaseType in (3, 5, 6 , 7 , 8 )
</select>
<select id="UnivstudyCheckByClass" parameterType="java.util.Map" resultType="AchiStatOfUid">
SELECT a.studentId , avg(b.score) as avgScore ,
count( distinct b.objectId ) as howmuch ,
count(b.objectId) as total ,
max(b.score) as maxScore,
max( b.created ) as lastTime
FROM UnivStudentOwnClass a
LEFT JOIN univAchivement b
ON a.studentId = b.uid
<if test="startTime!=null">
<![CDATA[
and b.created >= #{startTime}
]]>
</if>
<if test="endTime!=null">
<![CDATA[
and b.created < #{endTime}
]]>
</if>
AND b.achiveType in ('L','W')
AND pointCaseType in (3, 5, 6 , 7 ,8 )
AND b.objectId in
<foreach collection="lessonIds" item="item" separator="," close=")" open="(">
#{item}
</foreach>
WHERE a.classesId = #{classesId} and a.status = 1
GROUP BY a.studentId
<if test="pageSize!=null">
LIMIT #{pageSize}
</if>
<if test="offset!=null">
OFFSET #{offset}
</if>
</select>
<select id="UnivgetLessonIdByMultiUnitId" parameterType="java.util.List" resultType="java.lang.Integer">
SELECT a.lessonId
FROM Lesson a
WHERE a.parentId in
<foreach collection="list" index="index" item="item" separator="," close=")" open="(">
#{item}
</foreach>
</select>
<select id="UnivgetLessonIdByMultiBookId" parameterType="java.util.List" resultType="java.lang.Integer">
SELECT a.lessonId
FROM Lesson a
INNER JOIN Lesson b
on a.parentId = b.lessonId
WHERE b.parentId in
<foreach collection="list" index="index" item="item" separator="," close=")" open="(">
#{item}
</foreach>
</select>
<select id="UnivsingleTotalStatConnectLog" parameterType="java.util.Map" resultType="java.util.HashMap">
SELECT sum( c.timeLength ) as studyDuration
FROM univConnectLog c
WHERE c.uid = #{uid}
AND c.startTime &gt; #{startTime}
AND c.startTime &lt; #{endTime}
</select>
<select id="UnivsingleTotalStatAchive" parameterType="java.util.Map" resultType="java.util.HashMap">
SELECT case when round( avg( d.score ) ) is null then 0
else avg( d.score ) end as avgScore ,
count(d.achivementid) as studyNum
FROM univachivement d
WHERE d.uid = #{uid}
AND d.created &gt; #{startTime}
AND d.created &lt; #{endTime}
AND d.achiveType in ('L','W')
AND d.pointCaseType in (3, 5, 6 , 7 ,8 )
</select>
<select id="UnivgetTimeAxisByUid" parameterType="java.util.Map" resultType="java.util.HashMap">
<!-- select distinct(s.uid) as uid , sum(s.race) as raceCount ,
sum(s.achivement) as achivementCount , sum(s.exam) as examCount ,
s.month as month , s.year as year
from ( select uid, count(racescoreid) as race , 0 as achivement ,
0 as exam ,
extract(month from created) as month ,
extract(year from created) as year
from univracescore
where created &gt; #{startTime} and created &lt; #{endTime}
group by uid , extract(month from created) ,
extract(year from created)
union all
select distinct(uid) , 0 as race,
count(achivementid) as achivement ,
0 as exam ,
extract(month from created) as month ,
extract(year from created) as year
from univachivement
where created &gt; #{startTime} and created &lt; #{endTime}
and achivetype in ( 'L' , 'W' )
and pointCaseType in ( 3 , 5 , 6 , 7 , 8 )
group by uid ,extract(month from created) ,
extract(year from created)
union all
select distinct(userid) as uid , 0 as race , 0 as achivement ,
count(examanswerid) as exam ,
extract(month from created) as month ,
extract(year from created) as year
from univexamanswer
where created &gt; #{startTime} and created &lt; #{endTime}
group by userid ,extract(month from created) ,
extract(year from created)
) s
where uid =#{uid}
group by uid,month , year -->
select distinct(s.uid) as uid , sum(s.race) as raceCount , sum(s.achivement) as achivementCount , sum(s.exam) as examCount , sum(s.hearCount) as hearCount ,sum(s.hearexamcount) as hearexamcount,sum(s.synchroCount) synchroCount ,s.month as month , s.year as year from (
select uid, count(racescoreid) as race , 0 as achivement , 0 as exam , 0 as hearCount ,0 as hearexamcount,0 as synchroCount, extract(month from created) as month , extract(year from created) as year from univracescore
where created &gt; #{startTime} and created &lt; #{endTime} and uid=#{uid}
group by uid ,extract(month from created) , extract(year from created)
union all
select distinct(uid) , 0 as race, count(achivementid) as achivement , 0 as exam , 0 as hearCount ,0 as hearexamcount,0 as synchroCount, extract(month from created) as month , extract(year from created) as year from univachivement
where created &gt; #{startTime} and created &lt; #{endTime} and achivetype in ( 'L' , 'W' )
and pointCaseType in ( 3 , 5 , 6 , 7 , 8 ) and uid=#{uid}
group by uid ,extract(month from created) , extract(year from created)
union all
select distinct(ea.userid) as uid ,0 as race , 0 as achivement , count(ea.examanswerid) as exam ,0 as hearCount ,0 as hearexamcount,0 as synchroCount, extract(month from ea.created) as month , extract(year from ea.created) as year
from univexamanswer ea
inner join univexam e on ea.examid=e.examid and e.isOral = 1 and ea.userid = #{uid} and
ea.created &gt; #{startTime} and ea.created &lt; #{endTime}
group by userid ,extract(month from ea.created) , extract(year from ea.created)
union all
select distinct(ea.userid) as uid ,0 as race , 0 as achivement , 0 as exam ,0 as hearCount ,count(ea.examanswerid) as hearexamcount,0 as synchroCount, extract(month from ea.created) as month , extract(year from ea.created) as year
from univexamanswer ea
inner join univexam e on ea.examid=e.examid and e.isOral = 0 and ea.userid = #{uid} and
ea.created &gt; #{startTime} and ea.created &lt; #{endTime}
group by userid ,extract(month from ea.created) , extract(year from ea.created)
union all
select distinct(ea.userid) as uid ,0 as race , 0 as achivement , 0 as exam ,0 as hearCount ,0 as hearexamcount,count(ea.examanswerid) as synchroCount, extract(month from ea.created) as month , extract(year from ea.created) as year
from univexamanswer ea
inner join univexam e on ea.examid=e.examid and e.isOral = 3 and ea.userid = #{uid} and
ea.created &gt; #{startTime} and ea.created &lt; #{endTime}
group by userid ,extract(month from ea.created) , extract(year from ea.created)
union all
select distinct(ea.userid) as uid ,0 as race , 0 as achivement , 0 as exam ,count(ea.examanswerid) as hearCount ,0 as hearexamcount,0 as synchroCount, extract(month from ea.created) as month , extract(year from ea.created) as year
from univexamanswer ea
inner join univexam e on ea.examid=e.examid and e.isOral = 2 and ea.userid = #{uid} and
ea.created &gt; #{startTime} and ea.created &lt; #{endTime}
group by userid ,extract(month from ea.created) , extract(year from ea.created)
union all
select distinct(userid) as uid ,0 as race , 0 as achivement , 0 as exam ,count(examanswerid) as hearCount ,0 as hearexamcount,0 as synchroCount, extract(month from created) as month , extract(year from created) as year from univhearanswer
where created &gt; #{startTime} and created &lt; #{endTime} and userid = #{uid}
group by userid ,extract(month from created) , extract(year from created) ) s
where uid =#{uid}
group by uid,month , year
</select>
<!-- 根据地区统计高校的数据 -->
<select id="univStatByArea" resultType="java.util.HashMap">
select a.areaid , a.areaname ,
COALESCE( b.schoolcount , b.schoolcount , 0 ) as schoolcount
from ( select areaId , areaname , parentId
from Area
where parentId = 0 ) as a
left join ( select floor( areaId / 10000 ) * 10000 as tempId,
count(*) as schoolcount
from University
where status = 1
group by floor( areaId / 10000 ) * 10000 ) as b
on a.areaId = b.tempId
order by a.areaId
</select>
<select id="UnivstudyCheckByClassOfWord" parameterType="java.util.Map" resultType="AchiStatOfUid">
with temp as (
select wordsid from words w inner join univassigndetail a on a.assignmentId=#{assignmentId}
and w.lessonid=a.unitid ),
temp1 as (select count(wordsid) howmuch from temp)
SELECT a.studentId , round( avg(b.score) ) as avgScore ,
count( distinct b.wordsid ) as howmuch ,
count(b.wordsid) as total ,
max(b.score) as maxScore,
max( b.created ) as lastTime ,count( distinct b.wordsid )||'/'||(select * from temp1) as finishWords
FROM UnivStudentOwnClass a
inner join univstudent c on a.studentid=c.studentid and c.status=1
left JOIN univwordAchive b
ON a.studentId = b.uid
<if test="startTime!=null">
<![CDATA[
and b.created >= #{startTime}
]]>
</if>
<if test="endTime!=null">
<![CDATA[
and b.created < #{endTime}
]]>
</if>
AND b.wordsid in
(select wordsid from temp)
WHERE a.classesId = #{classesId} and a.status = 1
GROUP BY a.studentId
order by maxScore desc nulls last,avgScore desc nulls last,studentId
<if test="pageSize!=null">
LIMIT #{pageSize}
</if>
<if test="offset!=null">
OFFSET #{offset}
</if>
</select>
<select id="univStudyStatForExcel" parameterType="java.util.HashMap" resultType="java.util.HashMap">
SELECT a.uid , s.truename ,
a.unitId , u.lessonname as unitname , u.orderId as uOrder ,
a.lessonId , l.lessonname , l.orderId as lOrder ,
a.howmuch , a.maxscore , a.avgscore ,
b.lessonId as bookid , b.lessonname as bookname
FROM
(select m.uid , m.unitId , m.lessonId , count(*) as howmuch ,
max( m.score ) as maxscore , avg( m.score ) as avgscore
from
( select a1.uid , a1.objectId as unitId , 0 as lessonId , a1.score
from univStudentOwnClass sc1
inner join univAchivement a1
on sc1.classesId = #{classesId} and sc1.studentId = a1.uid
and a1.achiveType = 'W'
and a1.pointCaseType = 3
and a1.created &gt; #{startTime}
and a1.created &lt; #{endTime}
union
select a2.uid , l2.parentId as unitId , a2.objectId as lessonId , a2.score
from univStudentOwnClass sc2
inner join univAchivement a2
on sc2.classesId = #{classesId} and sc2.studentId = a2.uid
and a2.achiveType = 'L'
and a2.pointCaseType in ( 5 , 6 , 7 , 8 )
and a2.created &gt; #{startTime}
and a2.created &lt; #{endTime}
inner join Lesson l2
on a2.objectId = l2.lessonId ) as m
group by m.uid , m.unitId , m.lessonId ) as a
INNER JOIN univStudent as s
on a.uid = s.studentId
INNER JOIN Lesson as u
on a.unitId = u.lessonId
INNER JOIN Lesson as b
on u.parentId = b.lessonId
LEFT JOIN Lesson as l
on a.lessonId = l.lessonId
ORDER BY a.uid , u.orderId , l.orderId
</select>
<select id="UnivstudyCheckByClassTwo" parameterType="java.util.Map" resultType="AchiStatOfUid">
with temp as(select b.studentid from univstudentownclass s inner join univstudent b on
s.studentid=b.studentid and b.status=1 where s.classesid=#{classesId} and s.status=1),
temp1 as(select b.uuid,a.studentId,b.uid,b.score,b.created,objectid,
row_number() OVER (PARTITION BY a.studentId order by b.score desc , b.created asc ) as rn
from temp a left join univachivement b
ON a.studentId = b.uid
AND b.achiveType in ('L','W')
AND pointCaseType in (3, 5, 6 , 7 ,8 ) AND b.objectId in
<foreach item="item" index="index" collection="lessonIds"
open="(" separator="," close=")">
#{item}
</foreach>
<if test="startTime != null">
and b.created &gt;= #{startTime}
</if>
<if test="endTime != null">
and b.created &lt; #{endTime}
</if> ),
temp2 as(select uid,uuid from temp1 where rn=1 and length(uuid)>0 ),
temp3 as (SELECT studentId , avg(score) as avgScore ,count( distinct objectId ) as howmuch ,
count(objectId) as total , max(score) as maxScore, max( created ) as lastTime
FROM temp1 group by studentid)
select a.studentId,a.avgScore,a.howmuch,a.total,a.maxScore,a.lastTime,b.uuid voice from
temp3 a left join temp2 b on a.studentid=b.uid
ORDER BY maxScore desc nulls last,avgScore desc nulls last,a.studentId
<if test="pageSize!=null">
LIMIT #{pageSize}
</if>
<if test="offset!=null">
OFFSET #{offset}
</if>
</select>
</mapper>