<?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.reportrzs.mapper.RzsViewStatisticsInfoMapper">



		<!-- and month = #{month}  -->
	<select id="listForLast" resultType="map">
       select
        sum(total_cnt) total_cnt,city_name ,city_code 
        from rzs_view_statistics_info
        where 1=1 and year = #{year} and (area_code is not null and area_code != '') and patent_type='发明'
        group by city_name ,city_code
    </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>sum(total_cnt) total_cnt,
    	patent_type,year,sum(higher_school) higher_school,sum(research_institute) research_institute,
		sum(enterprise) enterprise,sum(institutions) institutions,sum(individual) individual
		  from rzs_view_statistics_info
		  where 1=1   and patent_type is not null 
		  <!-- 
		  <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>sum(total_cnt) total_cnt,
    	patent_type,year,sum(higher_school) higher_school,sum(research_institute) research_institute,
		sum(enterprise) enterprise,sum(institutions) institutions,sum(individual) individual
		  from rzs_view_statistics_info
		  where 1=1  and patent_type is not null 
		  <!-- 
		  <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>
     
</mapper>

