<?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.miaxis.question.mapper.QuestionWrongMapper">

    <resultMap type="QuestionWrong" id="QuestionWrongResult">
        <result property="id"    column="id"    />
        <result property="userId"    column="user_id"    />
        <result property="questionId"    column="question_id"    />
        <result property="km"    column="km"    />
        <result property="deviceType"    column="device_type"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectQuestionWrongVo">
        select * from question_wrong
    </sql>

    <select id="selectQuestionWrongList" parameterType="QuestionWrong" resultMap="QuestionWrongResult">
        <include refid="selectQuestionWrongVo"/>
        <where>
            <if test="userId != null and userId !='' "> and user_id = #{userId}</if>
            <if test="km != null and km!='' "> and km = #{km}</if>
            <if test="deviceType != null and deviceType!='' "> and q2.device_type = #{deviceType}</if>
        </where>
    </select>



    <select id="selectWrongIdByUserId" resultType="com.miaxis.question.vo.QuestionWrongIdDateVo">

        select q1.id,q2.create_time from question_info q1 join question_wrong q2 on q1.id = q2.question_id
        <where>
            <if test="userId != null and userId !='' "> and q2.user_id = #{userId}</if>
            <if test="km != null and km!='' "> and q2.km = #{km}</if>
            <if test="deviceType != null and deviceType!='' "> and q2.device_type = #{deviceType}</if>
        </where>
        order by q2.create_time
    </select>

    <select id="selectWrongCountByUserId" resultType="int">

        select count(1) from question_info q1 join question_wrong q2 on q1.id = q2.question_id
        <where>
            <if test="userId != null and userId !='' "> and q2.user_id = #{userId}</if>
            <if test="km != null and km!='' "> and q2.km = #{km}</if>
            <if test="deviceType != null and deviceType!='' "> and q2.device_type = #{deviceType}</if>
        </where>

    </select>

</mapper>
