<?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="test05.mapper.ScoreMapper">
    <select id="selectScore" resultType="test05.pojo.Score">
        SELECT N_STUDENT_ID AS studentId,
               N_COURSE_ID AS courseId,
               F_SCORE AS score
        FROM t_score
        WHERE #{studentId} in (N_STUDENT_ID, -1)
          AND #{courseId} in (N_COURSE_ID, -1)
          AND #{score} in (F_SCORE, -1);
    </select>
    <select id="selectScoreCount" resultType="java.lang.Integer">
        SELECT COUNT(*)
        FROM t_score
        WHERE #{studentId} in (N_STUDENT_ID, -1)
          AND #{courseId} in (N_COURSE_ID, -1)
          AND #{score} in (F_SCORE, -1);
    </select>
    <update id="updateScore">
        UPDATE t_score
        SET F_SCORE = #{score}
        WHERE N_COURSE_ID = #{courseId}
          AND N_STUDENT_ID = #{studentId}
    </update>
    <delete id="deleteScore">
        DELETE
        FROM t_score
        WHERE N_STUDENT_ID = #{studentId}
          AND N_COURSE_ID = #{courseId}
    </delete>
    <insert id="insertScore">
        INSERT INTO t_score
            (N_STUDENT_ID, N_COURSE_ID, F_SCORE)
        VALUES (#{studentId}, #{courseId}, #{score});
    </insert>
</mapper>