<?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.report.mapper.RzlViewStatisticsInfoMapper">


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


	<select id="listForLast" resultType="map">
       select
        sum(total_cnt) total_cnt,city_name ,city_code 
        from rzl_view_statistics_info
        where 1=1 and year = #{year} and month = #{month} 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 rzl_view_statistics_info
        where 1=1 
        <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='12'</if>
        <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 rzl_view_statistics_info
        where 1=1 
        <if test="maxYear != null  and maxYear != ''">and year<![CDATA[ = ]]>#{maxYear}</if>
        <if test="month != null  and month != '' ">and month<![CDATA[ = ]]>#{month}</if>
        <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>



