<?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.sundot.airport.system.mapper.portrait.EducationIndicatorMapper">

    <sql id="userIdsCondition">
        <foreach collection="userIds" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>
    </sql>

    <select id="queryPersonalEducation" resultType="String">
        SELECT schooling
        FROM sys_user
        WHERE user_id = #{userId}
          AND del_flag = '0'
    </select>

    <select id="queryOrgEducationStats" resultType="com.sundot.airport.system.domain.portrait.EducationStats">
        SELECT
        SUM(IF(schooling = '1', 1, 0)) AS primarySchoolCount,
        SUM(IF(schooling = '2', 1, 0)) AS middleSchoolCount,
        SUM(IF(schooling = '3', 1, 0)) AS highSchoolCount,
        SUM(IF(schooling = '4', 1, 0)) AS collegeCount,
        SUM(IF(schooling = '5', 1, 0)) AS bachelorCount,
        SUM(IF(schooling = '6', 1, 0)) AS masterCount,
        COUNT(*) AS total_count
        FROM sys_user
        WHERE del_flag = '0'
        AND status = '0'
        AND user_id IN
        <include refid="userIdsCondition"/>

    </select>

</mapper>