<?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="com.qmth.exam.reserve.dao.StudentDao">
    <select id="listNoFinishStudent" resultType="com.qmth.exam.reserve.entity.StudentEntity">
        SELECT s.id,s.apply_number,s.category_id
        FROM t_student s
                 LEFT JOIN (SELECT student_id, count(1) nums
                            FROM t_student_apply a
                            WHERE a.cancel = #{cancel}
                            GROUP BY student_id) ts ON ts.student_id = s.id
        WHERE apply_task_id = #{taskId}
          AND s.apply_number - ifnull(ts.nums, 0) > 0
    </select>

    <select id="findInfoById" resultType="com.qmth.exam.reserve.bean.student.StudentInfo">
        select stu.id,
               stu.name,
               stu.student_code,
               stu.identity_number,
               stu.photo_path,
               stu.gender,
               stu.apply_number,
               stu.open_id,
               stu.uid,
               stu.org_id,
               stu.apply_task_id,
               stu.category_id,
               c.name category_name
        from t_student stu
                 left join t_category c on c.id = stu.category_id
        where stu.id = #{studentId}
    </select>

    <select id="listNoFinishCategory" resultType="com.qmth.exam.reserve.bean.stdapply.CategoryVO">
        SELECT DISTINCT
            s.category_id id
        FROM
            t_category g,
            t_student s
                LEFT JOIN ( SELECT student_id, count( 1 ) nums FROM t_student_apply a WHERE a.cancel = #{cancel} GROUP BY student_id ) ts ON ts.student_id = s.id
        WHERE
            apply_task_id =  #{taskId}
          AND g.id = s.category_id
          AND g.ENABLE = 1
          AND s.apply_number - ifnull( ts.nums, 0 ) > 0
    </select>

</mapper>
