<?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="org.dromara.zjk.mapper.ZjkExpertMajorMapper">

    <select id="getExpertMajorCount" resultType="java.util.Map">
        SELECT
            min_degree AS degree,
            COUNT(*) AS count
        FROM
            (
                SELECT
                    zem.expert_id,
                    zem.tenant_id,
                    MIN(zem.DEGREE) AS min_degree,
                    ze.status
                FROM
                    zjk_expert_major zem
                        LEFT JOIN zjk_expert ze ON ze.expert_id = zem.expert_id
                WHERE
                    DEGREE IS NOT NULL
                  AND ze.status = 2
                GROUP BY
                    zem.expert_id,
                    zem.tenant_id,
                    ze.status) AS subquery
        GROUP BY
            min_degree
        ORDER BY
            min_degree;-- 按 min_degree 排序
    </select>
    <select id="selectMajorList" resultType="org.dromara.zjk.domain.ZjkExpertMajor">
        select zem.*
        from zjk_expert_major zem
        where zem.expert_id in
        <foreach collection="expertIds" open="(" separator="," close=")" item="expertId">
            #{expertId}
        </foreach>
    </select>
</mapper>
