<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN" "http://ibatis.apache.org/dtd/sql-map-2.dtd">
<sqlMap namespace="EaiSvcNameYearly">
  
  <statement id="selectByEaiSvcNameYearly" parameterClass="java.util.HashMap" resultClass="java.util.HashMap">
      SELECT A.STATCY AS "STATCY",
      A.EAISVCNAME AS "EAISVCNAME",
      A.YNTRSMTNOITM AS "YNTRSMTNOITM",
      A.YNERRNOITM AS "YNERRNOITM",
      COALESCE(B.EAISVCDESC, 'UNKNOWN') AS "EAISVCDESC", ROW_NUMBER() OVER()  AS "ROWNUM"
        FROM ( 
        	SELECT SUBSTR(STATCYM, 1, 4) AS STATCY,
      			EAISVCNAME,
				 (   SUM(S1MNTRSMTNOITM)  + SUM(S2MNTRSMTNOITM)  + SUM(S3MNTRSMTNOITM)
				   + SUM(S4MNTRSMTNOITM)  + SUM(S5MNTRSMTNOITM)  + SUM(S6MNTRSMTNOITM)
				   + SUM(S7MNTRSMTNOITM)  + SUM(S8MNTRSMTNOITM)  + SUM(S9MNTRSMTNOITM)
				   + SUM(S10MNTRSMTNOITM) + SUM(S11MNTRSMTNOITM) + SUM(S12MNTRSMTNOITM)
				 ) AS YNTRSMTNOITM,							
				 (   SUM(S1MNERRNOITM)  + SUM(S2MNERRNOITM)  + SUM(S3MNERRNOITM)
				   + SUM(S4MNERRNOITM)  + SUM(S5MNERRNOITM)  + SUM(S6MNERRNOITM)
				   + SUM(S7MNERRNOITM)  + SUM(S8MNERRNOITM)  + SUM(S9MNERRNOITM)
				   + SUM(S10MNERRNOITM) + SUM(S11MNERRNOITM) + SUM(S12MNERRNOITM)
				 ) AS YNERRNOITM
		         FROM $schemaId$.TSEAIST04
		         GROUP BY SUBSTR(STATCYM, 1, 4), EAISVCNAME
		         ORDER BY SUBSTR(STATCYM, 1, 4), EAISVCNAME
	        ) A
        LEFT OUTER JOIN $schemaId$.TSEAIHE01 B
        ON  A.EAISVCNAME = B.EAISVCNAME
        <dynamic prepend="WHERE">
	        <isNotEmpty prepend="AND" property="searchEaiBzwkDstcd">
			      TRIM(B.EAISVCDESC) LIKE CONCAT( '%',CONCAT( TRIM(#searchEaiBzwkDstcd#) , '%') )
			</isNotEmpty>
		</dynamic>
  </statement>
  
  <statement id="findByEaiSvcCodeYearlyObject2_1" parameterClass="java.util.HashMap" resultClass="com.eactive.eai.rms.onl.statistics.eaisvcname.vo.EaiSvcNameYearlyVO">
        SELECT A.ROWNUM AS "ROWNUM",
        A.STATCY AS "STATCY",
        A.EAISVCNAME AS "EAISVCNAME",
        A.YNTRSMTNOITM AS "YNTRSMTNOITM",
        COALESCE(B.EAISVCDESC, 'UNKNOWN') AS "EAISVCDESC"
        FROM ( 
        	SELECT ROW_NUMBER() OVER() ROWNUM, TMP1.*
	         FROM  ( 
	         	SELECT SUBSTR(STATCYM, 1, 4) AS STATCY,
	            EAISVCNAME,
				   (   SUM(S1MNTRSMTNOITM)  + SUM(S2MNTRSMTNOITM)  + SUM(S3MNTRSMTNOITM)
				     + SUM(S4MNTRSMTNOITM)  + SUM(S5MNTRSMTNOITM)  + SUM(S6MNTRSMTNOITM)
				     + SUM(S7MNTRSMTNOITM)  + SUM(S8MNTRSMTNOITM)  + SUM(S9MNTRSMTNOITM)
				     + SUM(S10MNTRSMTNOITM) + SUM(S11MNTRSMTNOITM) + SUM(S12MNTRSMTNOITM)
				   ) AS YNTRSMTNOITM
        		FROM $schemaId$.TSEAIST04
       			WHERE STATCYM LIKE CONCAT( '%' , CONCAT(#startDate# , '%'))
				<isNotEmpty prepend="AND" property="eaiSvcName">
				TRIM(EAISVCNAME) LIKE CONCAT( '%' , CONCAT( #eaiSvcName# , '%' ) )
				</isNotEmpty>
		        GROUP BY SUBSTR(STATCYM, 1, 4), EAISVCNAME
		        ORDER BY YNTRSMTNOITM DESC
      		)  TMP1
        ) A
		LEFT OUTER JOIN $schemaId$.TSEAIHE01 B
		ON  A.EAISVCNAME = B.EAISVCNAME
        WHERE ROWNUM &lt; 20+1
		ORDER BY ROWNUM
  </statement>
  
  <statement id="findByEaiSvcCodeYearlyObject2_2" parameterClass="java.util.HashMap" resultClass="com.eactive.eai.rms.onl.statistics.eaisvcname.vo.EaiSvcNameYearlyVO">
        SELECT A.ROWNUM AS "ROWNUM",
        A.STATCY AS "STATCY",
        A.EAISVCNAME AS "EAISVCNAME",
        A.YNERRNOITM AS "YNERRNOITM",
        COALESCE(B.EAISVCDESC, 'UNKNOWN') AS "EAISVCDESC"
        FROM ( 
        	SELECT ROW_NUMBER() OVER() ROWNUM, TMP1.*
			FROM  ( SELECT SUBSTR(STATCYM, 1, 4) AS STATCY,
			EAISVCNAME,
           (   SUM(S1MNERRNOITM)  + SUM(S2MNERRNOITM)  + SUM(S3MNERRNOITM)
             + SUM(S4MNERRNOITM)  + SUM(S5MNERRNOITM)  + SUM(S6MNERRNOITM)
             + SUM(S7MNERRNOITM)  + SUM(S8MNERRNOITM)  + SUM(S9MNERRNOITM)
             + SUM(S10MNERRNOITM) + SUM(S11MNERRNOITM) + SUM(S12MNERRNOITM)
           ) AS YNERRNOITM
           FROM $schemaId$.TSEAIST04
          	WHERE STATCYM LIKE CONCAT( '%' , CONCAT( #startDate# , '%') )
			<isNotEmpty prepend="AND" property="eaiSvcName">
			TRIM(EAISVCNAME) LIKE CONCAT( '%', CONCAT( #eaiSvcName# , '%'))
			</isNotEmpty>
			GROUP BY SUBSTR(STATCYM, 1, 4), EAISVCNAME
			ORDER BY YNERRNOITM DESC
         )  TMP1
       ) A
		LEFT OUTER JOIN $schemaId$.TSEAIHE01 B
		ON  A.EAISVCNAME = B.EAISVCNAME
        WHERE ROWNUM &lt; 20+1
		ORDER BY ROWNUM
  </statement>
</sqlMap>
