<?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.yida.data.school.news.mapper.EduSchoolMatterGroupMapper">
  <select id="listMatterGroup" resultType="com.yida.data.school.vo.index.MatterGroupInfoVO">
    select esmg.id,esmg.name,ifnull(sum( if(esmmg.id is not null ,1,0)),0) count
    from edu_school_matter_group esmg
    left join edu_school_matter_matter_group esmmg on esmg.id =esmmg.matter_group_id
    left join (select id from edu_school_matter where del_flag=0) esm on esmmg.matter_id=esm.id
    <where>
      esmg.del_flag=0
      <if test="schoolId != null">
        and esmg.school_id=#{schoolId}
      </if>
      <if test="type != null">
        and esmg.type=#{type}
      </if>
    </where>
    group by esmg.id,esmg.name,esmg.create_date
    order by esmg.create_date desc
  </select>
</mapper>
