INSERT INTO UnivFinishLessonStat ( uid, unitId, content, lessonCount, completeCount, created, howmuch, maxScore, avgScore , areaid ) Values ( #{uid}, #{unitId}, #{content}, #{lessonCount}, #{completeCount},current_timestamp, #{howmuch}, #{maxScore}, #{avgScore} , #{areaid} )
UPDATE UnivFinishLessonStat SET
uid = #{uid}, unitId = #{unitId}, content = #{content}, lessonCount = #{lessonCount}, completeCount = #{completeCount}, created = #{created}, howmuch = #{howmuch}, maxScore = #{maxScore}, avgScore = #{avgScore} , areaid = #{areaid}
where uid=#{uid} and areaid = #{areaid}
delete from UnivFinishLessonStat where 1=0
or (uid = #{item.uid} and unitid = #{item.unitId})
Insert into UnivFinishLessonStat ( uid , unitId , content , lessonCount ,
completeCount , created , howmuch , maxScore , avgScore , areaid )
select l.uid , l.unitId , m.lessonName , n.lessonCount ,
l.finishCount , current_timestamp , l.howmuch , l.maxScore , l.avgScore , l.areaid
from
( select a.uid , c.parentId as unitId , count( distinct c.lessonId ) as finishCount ,
count(*) as howmuch , max( score ) as maxScore , avg( score ) as avgScore , a.areaid
from UnivAchivement a
inner join Lesson c
on a.achiveType = 'L' and a.pointCaseType in ( 5, 6 ,7 , 8 )
and a.objectId = c.lessonId
group by a.uid , c.parentId , a.areaid) l
inner join Lesson m
on l.unitId = m.lessonId
inner join ( select parentId , count(*) as lessonCount
from Lesson
group by parentId ) n
on l.unitId = n.parentId
where 1=0
or (uid = #{item.uid} and unitid = #{item.unitId})