<?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.goldenwater.gx.mapper.GxStWryMapper">

    <resultMap type="com.goldenwater.gx.domain.GxStWry" id="GxStWryResult">
        <result property="bizCode"      column="biz_code"      />
        <result property="stnm"         column="stnm"          />
        <result property="year"         column="year"          />
        <result property="cod"          column="cod"           />
        <result property="nh3"          column="nh3"           />
        <result property="tn"           column="tn"            />
        <result property="tp"           column="tp"            />
    </resultMap>

    <select id="selectWryLatestByBizCode" parameterType="String" resultMap="GxStWryResult">
        SELECT * FROM (
            SELECT t.*, ROW_NUMBER() OVER(PARTITION BY t.stnm ORDER BY t.year DESC) rn
            FROM gx_st_wry t
            WHERE t.biz_code = #{bizCode}
        ) tmp
        WHERE rn = 1
        ORDER BY tmp.stcd asc
    </select>

    <select id="selectWryHistoryByBizCodeAndStnm" parameterType="map" resultMap="GxStWryResult">
        SELECT * FROM gx_st_wry
        WHERE biz_code = #{bizCode} AND stnm = #{stnm}
        ORDER BY year DESC
    </select>

</mapper>
