<?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="EaiSvcNameCompareMonthly">
  
  <statement id="findByTransactionEaiSvcNameMonthly" parameterClass="java.util.HashMap" resultClass="com.eactive.eai.rms.onl.statistics.eaisvcname.vo.EaiSvcNameCompareMonthlyVO">
        SELECT A.EAISVCNAME AS "EAISVCNAME",
         A.THISMONTHPROCCOLUMNNAME AS "THISMONTHPROCCOLUMNNAME",
         A.LASTMONTHPROCCOLUMNNAME AS "LASTMONTHPROCCOLUMNNAME",
        COALESCE(B.EAISVCDESC, 'UNKNOWN') AS "EAISVCDESC", 
        ROWNUM AS "ROWNUM"
        FROM ( 
        	SELECT A.EAISVCNAME,
			COALESCE(A.$thisMonthProcColumnName$, 0) AS THISMONTHPROCCOLUMNNAME,
			COALESCE(B.$lastMonthProcColumnName$, 0) AS LASTMONTHPROCCOLUMNNAME
			FROM ( 
				SELECT EAISVCNAME,
				SUM($thisMonthProcColumnName$) AS $thisMonthProcColumnName$
				FROM $schemaId$.TSEAIST04
				WHERE STATCYM BETWEEN #thisYear# AND #thisYear#
				GROUP BY EAISVCNAME
			) A  LEFT OUTER JOIN ( 
				SELECT EAISVCNAME,
				SUM($lastMonthProcColumnName$) AS $lastMonthProcColumnName$
				FROM $schemaId$.TSEAIST04
				WHERE STATCYM BETWEEN #lastYear# AND #lastYear#
				GROUP BY EAISVCNAME
			) B
			ON  A.EAISVCNAME = B.EAISVCNAME
		) A
		LEFT OUTER JOIN $schemaId$.TSEAIHE01 B
		ON A.EAISVCNAME = B.EAISVCNAME
    </statement>
</sqlMap>
