<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="jnpf.cultivate.mapper.FtbCultivateChapterTestResultMapper">
    <!--根据课程ID和用户ID查询章节测试结果列表-->
  <select id="selectChatperList" resultType="jnpf.model.cultivate.po.course.FtbCultivateChapterTestResult">
    SELECT
    t.F_CourseId courseId,
    t.F_CourseChapterId courseChapterId,
    t.F_UserId userId,
    t.F_ChapterTestOptions chapterTestOptions
    FROM
    ( SELECT *, ROW_NUMBER() OVER ( PARTITION BY F_UserId, F_CourseId,F_CourseChapterId ORDER BY F_CreatorTime DESC ) AS rn FROM ftb_cultivate_chapter_test_result
   <where>
     <if test="courseId != null and courseId != ''">
       and F_CourseId = #{courseId}
     </if>
     <if test="userId != null and userId != ''">
       and  F_UserId = #{userId}
     </if>
   </where>
    ) t
    where
    t.F_EnabledMark = 0 and   t.rn = 1
    </select>
</mapper>