<?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.reportpub.mapper.RzgViewStatisticsInfoMapper">

  <select id="selectYearList" resultType="map">
        select distinct `year`
        from rzg_view_statistics_info
        where `year` >= #{year}
        order by `year`
    </select>

<select id="listByReport" resultType="map">
        (select
        <if test="cityCode != null  and cityCode != ''">area_name ,area_code,</if>
        <if test="cityCode == null  or cityCode == ''">city_name area_name ,city_code area_code ,</if>
        patent_type,year,sum(total_cnt) total_cnt,
        sum(higher_school) higher_school,
        sum(research_institute) research_institute,
        sum(enterprise) enterprise,
        sum(institutions) institutions,
        sum(individual) individual
        from rzg_view_statistics_info
        where 1=1 
        and city_code is not null and city_code !=''
        <!-- 
        <if test="cityCode != null  and cityCode != ''">and area_name is not null and area_name !='' </if> 
         -->
         and `year` >= #{minYear} and `year`<![CDATA[ < ]]>#{maxYear}
        <if test="cityCode != null  and cityCode != '' ">and city_code = #{cityCode}</if>
        group by
        <if test="cityCode != null  and cityCode != ''">area_name,area_code</if>
        <if test="cityCode == null  or cityCode == ''">city_name,city_code</if>
        ,patent_type,year 
        ) union all (select
        <if test="cityCode != null  and cityCode != ''">area_name ,area_code,</if>
        <if test="cityCode == null  or cityCode == ''">city_name area_name  ,city_code area_code,</if>
        patent_type,year,sum(total_cnt) total_cnt,
        sum(higher_school) higher_school,
        sum(research_institute) research_institute,
        sum(enterprise) enterprise,
        sum(institutions) institutions,
        sum(individual) individual
        from rzg_view_statistics_info
        where 1=1   and city_code is not null and city_code !=''
        <!-- 
        <if test="cityCode != null  and cityCode != ''">and area_name is not null and area_name !='' </if> 
         -->
         and year = #{maxYear} and month<![CDATA[ <= ]]>#{month}
        <if test="cityCode != null  and cityCode != '' ">and city_code = #{cityCode}</if>
        group by
        <if test="cityCode != null  and cityCode != ''">area_name,area_code</if>
        <if test="cityCode == null  or cityCode == ''">city_name,city_code</if>
        ,patent_type,year 
        )
        
    </select>
<!-- 
<select id="listByReport" resultType="map">
        select
        <if test="cityCode != null  and cityCode != ''">area_name ,</if>
        <if test="cityCode == null  or cityCode == ''">city_name area_name ,</if>
        patent_type,year,
        sum(higher_school) higher_school,
        sum(research_institute) research_institute,
        sum(enterprise) enterprise,
        sum(institutions) institutions,
        sum(individual) individual
        from rzg_view_statistics_info
        where 1=1 and area_name is not null
        <if test="minYear != null  and minYear != ''">and year >= #{minYear}</if>
        <if test="maxYear != null  and maxYear != ''">and year<![CDATA[ <= ]]>#{maxYear}</if>
        <if test="month != null  and month != '' ">and month=#{month}</if>
        <if test="cityCode != null  and cityCode != '' ">and city_code = #{cityCode}</if>
        group by
        <if test="cityCode != null  and cityCode != ''">area_name</if>
        <if test="cityCode == null  or cityCode == ''">city_name</if>
        ,patent_type,year
    </select>
     -->
    
</mapper>