StudentMapper.xml 9.13 KB
<?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.jevon.mapper.StudentMapper" >
  <resultMap id="BaseResultMap" type="com.jevon.model.Student" >
    <id column="id" property="id" jdbcType="INTEGER" />
    <result column="open_id" property="analyseId" jdbcType="INTEGER" />
    <result column="school_name" property="schoolName" jdbcType="VARCHAR" />
    <result column="class_name" property="className" jdbcType="VARCHAR" />
    <result column="student_name" property="studentName" jdbcType="VARCHAR" />
    <result column="student_number" property="studentNumber" jdbcType="VARCHAR" />
    <result column="analyse_id" property="analyseId" jdbcType="INTEGER" />
    <result column="score" property="score" jdbcType="FLOAT" />
    <result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
  </resultMap>

    <insert id="insertBatch" parameterType="java.util.List">
    insert into sz_learn_student (school_name, class_name,student_name,
    student_number,analyse_id,score,create_time)
    values
     <foreach collection="list" item="emp" separator=",">
       (#{emp.schoolName},#{emp.className},#{emp.studentName},
       #{emp.studentNumber},#{emp.analyseId},#{emp.score},#{emp.createTime})
     </foreach>
    </insert>

    <select id="selectByStudent" parameterType="com.jevon.model.Student"  resultMap="BaseResultMap">
    select * from sz_learn_student
    <where>
        <if test="analyseId != 0">
          and analyse_id = #{analyseId}
        </if>
        <if test="schoolName != null">
          and school_name = #{schoolName}
        </if>
        <if test="className != null">
          and class_name = #{className}
        </if>
        <if test="schoolNames != null and schoolNames.size()>0">
            AND school_name IN
            <foreach item="item" index="index" collection="schoolNames" open="("  close=")" separator=",">
                #{item}
            </foreach>
        </if>
    </where>
    order by score desc
    </select>

    <select id="selectCountByScore" parameterType="com.jevon.model.Student"  resultType="java.lang.Integer">
        select count(1) from sz_learn_student
        <where>
            <if test="analyseId != 0">
                and analyse_id = #{analyseId}
            </if>
            <if test="schoolName != null">
                and school_name = #{schoolName}
            </if>
            <if test="className != null">
                and class_name = #{className}
            </if>
            <if test="begin != null">
                and score <![CDATA[ >= ]]> #{begin}
            </if>
            <if test="end != null">
                and score <![CDATA[ < ]]> #{end}
            </if>
            <if test="schoolNames != null and schoolNames.size()>0">
                AND school_name IN
                <foreach item="item" index="index" collection="schoolNames" open="("  close=")" separator=",">
                    #{item}
                </foreach>
            </if>
        </where>
    </select>

    <select id="selectClassNameBySchool" parameterType="com.jevon.model.Student" resultType="java.lang.String">
    select DISTINCT(class_name) from sz_learn_student where analyse_id = #{analyseId}
      and school_name = #{schoolName}
    </select>

    <select id="selectSchoolNameByAnalyse" parameterType="java.lang.Integer" resultType="java.lang.String">
        select DISTINCT(school_name) from sz_learn_student where analyse_id = #{analyseId}
    </select>

    <select id="selectMaxScore" parameterType="com.jevon.model.Student" resultType="java.lang.Double">
        select max(score) from sz_learn_student
        <where>
            <if test="analyseId != 0">
                and analyse_id = #{analyseId}
            </if>
            <if test="schoolName != null">
                and school_name = #{schoolName}
            </if>
            <if test="schoolNames != null and schoolNames.size()>0">
                AND school_name IN
                <foreach item="item" index="index" collection="schoolNames" open="("  close=")" separator=",">
                    #{item}
                </foreach>
            </if>
        </where>
    </select>

    <select id="selectMinScore" parameterType="com.jevon.model.Student" resultType="java.lang.Double">
        select min(score) from sz_learn_student
        <where>
            <if test="analyseId != 0">
                and analyse_id = #{analyseId}
            </if>
            <if test="schoolName != null">
                and school_name = #{schoolName}
            </if>
            <if test="schoolNames != null and schoolNames.size()>0">
                AND school_name IN
                <foreach item="item" index="index" collection="schoolNames" open="("  close=")" separator=",">
                    #{item}
                </foreach>
            </if>
        </where>
    </select>

    <select id="selectAvgScore" parameterType="com.jevon.model.Student" resultType="java.lang.Double">
        select avg(score) from sz_learn_student
        <where>
            <if test="analyseId != 0">
                and analyse_id = #{analyseId}
            </if>
            <if test="schoolName != null">
                and school_name = #{schoolName}
            </if>
            <if test="schoolNames != null and schoolNames.size()>0">
                AND school_name IN
                <foreach item="item" index="index" collection="schoolNames" open="("  close=")" separator=",">
                    #{item}
                </foreach>
            </if>
        </where>
    </select>

    <select id="selectModeNumber" parameterType="com.jevon.model.Student" resultType="java.lang.Double">
        SELECT score FROM sz_learn_student
        <where>
            <if test="analyseId != 0">
                and analyse_id = #{analyseId}
            </if>
            <if test="schoolName != null">
                and school_name = #{schoolName}
            </if>
            <if test="schoolNames != null and schoolNames.size()>0">
                AND school_name IN
                <foreach item="item" index="index" collection="schoolNames" open="("  close=")" separator=",">
                    #{item}
                </foreach>
            </if>
        </where>
        GROUP BY score
        HAVING COUNT ( * ) >= (
        SELECT MAX( cnt ) FROM
        (
        SELECT COUNT ( * ) cnt FROM sz_learn_student
        <where>
            <if test="analyseId != 0">
                and analyse_id = #{analyseId}
            </if>
            <if test="schoolName != null">
                and school_name = #{schoolName}
            </if>
            <if test="schoolNames != null and schoolNames.size()>0">
                AND school_name IN
                <foreach item="item" index="index" collection="schoolNames" open="("  close=")" separator=",">
                    #{item}
                </foreach>
            </if>
        </where>
        GROUP BY score ) tmp
        )
    </select>

    <select id="selectMedian" parameterType="com.jevon.model.Student" resultType="java.lang.Double">
        SELECT
        avg(DISTINCT score)
        FROM (
        select T1.score from  sz_learn_student T1 , sz_learn_student T2
        <where>
            <if test="analyseId != 0">
                and T1.analyse_id = #{analyseId}
            </if>
            <if test="schoolName != null">
                and T1.school_name = #{schoolName}
            </if>
            <if test="analyseId != 0">
                and T2.analyse_id = #{analyseId}
            </if>
            <if test="schoolName != null">
                and T2.school_name = #{schoolName}
            </if>
            <if test="schoolNames != null and schoolNames.size()>0">
                AND T1.school_name IN
                <foreach item="item" index="index" collection="schoolNames" open="("  close=")" separator=",">
                    #{item}
                </foreach>
            </if>
            <if test="schoolNames != null and schoolNames.size()>0">
                AND T2.school_name IN
                <foreach item="item" index="index" collection="schoolNames" open="("  close=")" separator=",">
                    #{item}
                </foreach>
            </if>
        </where>
        GROUP BY
        T1.score
        HAVING
        sum(case when T2.score <![CDATA[ >= ]]> T1.score then 1 else 0 end) >= count(*)/2
        and sum(case when T2.score <![CDATA[ <= ]]> T1.score then 1 else 0 end)>= count(*)/2) tmp
    </select>
    
    <select id="selectStdev" parameterType="com.jevon.model.Student" resultType="java.lang.Double">
        select STDEVP(score) from sz_learn_student
        <where>
            <if test="analyseId != 0">
                and analyse_id = #{analyseId}
            </if>
            <if test="schoolName != null">
                and school_name = #{schoolName}
            </if>
            <if test="schoolNames != null and schoolNames.size()>0">
                AND school_name IN
                <foreach item="item" index="index" collection="schoolNames" open="("  close=")" separator=",">
                    #{item}
                </foreach>
            </if>
        </where>
    </select>
</mapper>