<?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.ruoyi.agentrep.mapper.DAgentAuthInfoMapper">

    <select id="queryAgentRep" resultType="map">
        <![CDATA[
		     select * from (
		   select  agency_name,count(*) all_total,
sum(case patent_type when '1' then 1 when '2' then 1 when '3' then 1 else 0 end ) pub_total
,sum(case patent_type when '2' then 1 when '3' then 1 when '4' then 1 else 0 end ) auth_total
,sum(case  when patent_type='4' then 1 else 0 end ) invention_cnt  
,sum(case  when patent_type='2' then 1 else 0 end ) model_utility_cnt 
,sum(case  when patent_type='3'   then 1 else 0 end ) appearance_cnt 
from d_patent_pub_info where agency_name <>'' ]]>
        <if test="beginDate != null  and beginDate != ''">and app_date>=#{beginDate}</if>
        <if test="endDate != null  and endDate != ''">and app_date<![CDATA[<=]]>#{endDate}</if>
        
        <if test="cityCode != null  and cityCode != ''">and modify_appli_city_code=#{cityCode}</if>
        
        group by agency_name
        ) ff order by ff.all_total desc limit 100
    </select>


</mapper>