<?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="BjobBzwkDstcdMonthly">
  
  <statement id="selectListCount" parameterClass="java.util.HashMap" resultClass="java.util.HashMap">
        SELECT COUNT(*) AS "TOTALCOUNT"
        	 , SUM(MNTRSMTNOITM1)	AS "MNTRSMTNOITM1_SUM"
             , SUM(MNERRNOITM1)		AS "MNERRNOITM1_SUM"
			 , SUM(MNTRSMTNOITM2)	AS "MNTRSMTNOITM2_SUM"
             , SUM(MNERRNOITM2)		AS "MNERRNOITM2_SUM"
			 , SUM(MNTRSMTNOITM3)	AS "MNTRSMTNOITM3_SUM"
             , SUM(MNERRNOITM3)		AS "MNERRNOITM3_SUM"
			 , SUM(MNTRSMTNOITM4)	AS "MNTRSMTNOITM4_SUM"
             , SUM(MNERRNOITM4)		AS "MNERRNOITM4_SUM"
			 , SUM(MNTRSMTNOITM5)	AS "MNTRSMTNOITM5_SUM"
             , SUM(MNERRNOITM5)		AS "MNERRNOITM5_SUM"
			 , SUM(MNTRSMTNOITM6)	AS "MNTRSMTNOITM6_SUM"
             , SUM(MNERRNOITM6)		AS "MNERRNOITM6_SUM"
			 , SUM(MNTRSMTNOITM7)	AS "MNTRSMTNOITM7_SUM"
             , SUM(MNERRNOITM7)		AS "MNERRNOITM7_SUM"
			 , SUM(MNTRSMTNOITM8)	AS "MNTRSMTNOITM8_SUM"
             , SUM(MNERRNOITM8)		AS "MNERRNOITM8_SUM"
			 , SUM(MNTRSMTNOITM9)	AS "MNTRSMTNOITM9_SUM"
             , SUM(MNERRNOITM9)		AS "MNERRNOITM9_SUM"
			 , SUM(MNTRSMTNOITM10)	AS "MNTRSMTNOITM10_SUM"
             , SUM(MNERRNOITM10)	AS "MNERRNOITM10_SUM"
			 , SUM(MNTRSMTNOITM11)	AS "MNTRSMTNOITM11_SUM"
             , SUM(MNERRNOITM11)	AS "MNERRNOITM11_SUM"
			 , SUM(MNTRSMTNOITM12)	AS "MNTRSMTNOITM12_SUM"
             , SUM(MNERRNOITM12)	AS "MNERRNOITM12_SUM"        
          FROM (
				SELECT
			        NVL(SUM(CASE WHEN MM = '01' THEN ProcCount END), 0)    AS "MNTRSMTNOITM1" 
			      , NVL(SUM(CASE WHEN MM = '01' THEN ErrCount END), 0)     AS "MNERRNOITM1"   
			      , NVL(SUM(CASE WHEN MM = '02' THEN ProcCount END), 0)    AS "MNTRSMTNOITM2" 
			      , NVL(SUM(CASE WHEN MM = '02' THEN ErrCount END), 0)     AS "MNERRNOITM2"   
			      , NVL(SUM(CASE WHEN MM = '03' THEN ProcCount END), 0)    AS "MNTRSMTNOITM3" 
			      , NVL(SUM(CASE WHEN MM = '03' THEN ErrCount END), 0)     AS "MNERRNOITM3"   
			      , NVL(SUM(CASE WHEN MM = '04' THEN ProcCount END), 0)    AS "MNTRSMTNOITM4" 
			      , NVL(SUM(CASE WHEN MM = '04' THEN ErrCount END), 0)     AS "MNERRNOITM4"   
			      , NVL(SUM(CASE WHEN MM = '05' THEN ProcCount END), 0)    AS "MNTRSMTNOITM5" 
			      , NVL(SUM(CASE WHEN MM = '05' THEN ErrCount END), 0)     AS "MNERRNOITM5"   
			      , NVL(SUM(CASE WHEN MM = '06' THEN ProcCount END), 0)    AS "MNTRSMTNOITM6" 
			      , NVL(SUM(CASE WHEN MM = '06' THEN ErrCount END), 0)     AS "MNERRNOITM6"   
			      , NVL(SUM(CASE WHEN MM = '07' THEN ProcCount END), 0)    AS "MNTRSMTNOITM7" 
			      , NVL(SUM(CASE WHEN MM = '07' THEN ErrCount END), 0)     AS "MNERRNOITM7"   
			      , NVL(SUM(CASE WHEN MM = '08' THEN ProcCount END), 0)    AS "MNTRSMTNOITM8" 
			      , NVL(SUM(CASE WHEN MM = '08' THEN ErrCount END), 0)     AS "MNERRNOITM8"   
			      , NVL(SUM(CASE WHEN MM = '09' THEN ProcCount END), 0)    AS "MNTRSMTNOITM9" 
			      , NVL(SUM(CASE WHEN MM = '09' THEN ErrCount END), 0)     AS "MNERRNOITM9"   
			      , NVL(SUM(CASE WHEN MM = '10' THEN ProcCount END), 0)    AS "MNTRSMTNOITM10"
			      , NVL(SUM(CASE WHEN MM = '10' THEN ErrCount END), 0)     AS "MNERRNOITM10"  
			      , NVL(SUM(CASE WHEN MM = '11' THEN ProcCount END), 0)    AS "MNTRSMTNOITM11"
			      , NVL(SUM(CASE WHEN MM = '11' THEN ErrCount END), 0)     AS "MNERRNOITM11"  
			      , NVL(SUM(CASE WHEN MM = '12' THEN ProcCount END), 0)    AS "MNTRSMTNOITM12"
			      , NVL(SUM(CASE WHEN MM = '12' THEN ErrCount END), 0)     AS "MNERRNOITM12"  
				FROM
			        (
			        SELECT  SUBSTR(FileTrsmtStartHMS, 1, 4) AS StatcY
			              , SUBSTR(FileTrsmtStartHMS, 5, 2) AS MM
			              , BJ08.BjobBzwkDstcd
			              , BJ02.BjobBzwkName 
			        	  , SUM(CASE WHEN ThisStgePrcssRsultCd = 'E' THEN 0 ELSE 1 END) AS ProcCount
			              , SUM(CASE WHEN ThisStgePrcssRsultCd = 'E' THEN 1 ELSE 0 END) AS ErrCount
			        FROM  $schemaId$.TSEAIBJ08 BJ08, $schemaId$.TSEAIBJ02 BJ02
			        WHERE BJ08.FileTrsmtStartHMS &gt;= #searchStart# ||'0000000000'
			        AND   BJ08.FileTrsmtStartHMS &lt;= #searchEnd# ||'9999999999'
			        AND   BJ08.BjobBzwkDstcd = BJ02.BjobBzwkDstcd
						<isNotEmpty prepend="AND" property="searchEaiBzwkDstcd">
						(  TRIM(BJ08.BjobBzwkDstcd) LIKE CONCAT( '%',CONCAT( UPPER(#searchEaiBzwkDstcd#) , '%') ) OR
							  BJ02.BjobBzwkName LIKE CONCAT( '%',CONCAT( UPPER(#searchEaiBzwkDstcd#) , '%') )   )
						</isNotEmpty>
			        GROUP BY
			                SUBSTR(FileTrsmtStartHMS, 1, 4)
			              , SUBSTR(FileTrsmtStartHMS, 5, 2)
			              , BJ08.BjobBzwkDstcd, BJ02.BjobBzwkName
			        ) TMP1
				GROUP BY StatcY, BjobBzwkDstcd, BjobBzwkName
			)
			
  </statement>
  
  <statement id="selectByEaiBzwkDstcdMonthly" parameterClass="java.util.HashMap" resultClass="java.util.HashMap">
		SELECT
           STATCY         AS "STATCY"
           , BJOBBZWKDSTCD   AS "BJOBBZWKDSTCD"
           , BJOBBZWKNAME   AS "BJOBBZWKNAME"
		      , NVL(SUM(CASE WHEN MM = '01' THEN ProcCount END), 0)    AS "MNTRSMTNOITM1" 
		      , NVL(SUM(CASE WHEN MM = '01' THEN ErrCount END), 0)     AS "MNERRNOITM1"   
		      , NVL(SUM(CASE WHEN MM = '02' THEN ProcCount END), 0)    AS "MNTRSMTNOITM2" 
		      , NVL(SUM(CASE WHEN MM = '02' THEN ErrCount END), 0)     AS "MNERRNOITM2"   
		      , NVL(SUM(CASE WHEN MM = '03' THEN ProcCount END), 0)    AS "MNTRSMTNOITM3" 
		      , NVL(SUM(CASE WHEN MM = '03' THEN ErrCount END), 0)     AS "MNERRNOITM3"   
		      , NVL(SUM(CASE WHEN MM = '04' THEN ProcCount END), 0)    AS "MNTRSMTNOITM4" 
		      , NVL(SUM(CASE WHEN MM = '04' THEN ErrCount END), 0)     AS "MNERRNOITM4"   
		      , NVL(SUM(CASE WHEN MM = '05' THEN ProcCount END), 0)    AS "MNTRSMTNOITM5" 
		      , NVL(SUM(CASE WHEN MM = '05' THEN ErrCount END), 0)     AS "MNERRNOITM5"   
		      , NVL(SUM(CASE WHEN MM = '06' THEN ProcCount END), 0)    AS "MNTRSMTNOITM6" 
		      , NVL(SUM(CASE WHEN MM = '06' THEN ErrCount END), 0)     AS "MNERRNOITM6"   
		      , NVL(SUM(CASE WHEN MM = '07' THEN ProcCount END), 0)    AS "MNTRSMTNOITM7" 
		      , NVL(SUM(CASE WHEN MM = '07' THEN ErrCount END), 0)     AS "MNERRNOITM7"   
		      , NVL(SUM(CASE WHEN MM = '08' THEN ProcCount END), 0)    AS "MNTRSMTNOITM8" 
		      , NVL(SUM(CASE WHEN MM = '08' THEN ErrCount END), 0)     AS "MNERRNOITM8"   
		      , NVL(SUM(CASE WHEN MM = '09' THEN ProcCount END), 0)    AS "MNTRSMTNOITM9" 
		      , NVL(SUM(CASE WHEN MM = '09' THEN ErrCount END), 0)     AS "MNERRNOITM9"   
		      , NVL(SUM(CASE WHEN MM = '10' THEN ProcCount END), 0)    AS "MNTRSMTNOITM10"
		      , NVL(SUM(CASE WHEN MM = '10' THEN ErrCount END), 0)     AS "MNERRNOITM10"  
		      , NVL(SUM(CASE WHEN MM = '11' THEN ProcCount END), 0)    AS "MNTRSMTNOITM11"
		      , NVL(SUM(CASE WHEN MM = '11' THEN ErrCount END), 0)     AS "MNERRNOITM11"  
		      , NVL(SUM(CASE WHEN MM = '12' THEN ProcCount END), 0)    AS "MNTRSMTNOITM12"
		      , NVL(SUM(CASE WHEN MM = '12' THEN ErrCount END), 0)     AS "MNERRNOITM12"  
		FROM
	        (
	        SELECT
	                SUBSTR(FileTrsmtStartHMS, 1, 4) AS StatcY
	              , SUBSTR(FileTrsmtStartHMS, 5, 2) AS MM
	              , BJ08.BjobBzwkDstcd
	              , BJ02.BjobBzwkName
	              , SUM(CASE WHEN ThisStgePrcssRsultCd = 'E' THEN 0 ELSE 1 END) AS ProcCount
	              , SUM(CASE WHEN ThisStgePrcssRsultCd = 'E' THEN 1 ELSE 0 END) AS ErrCount
	        FROM  $schemaId$.TSEAIBJ08 BJ08, $schemaId$.TSEAIBJ02 BJ02
	        WHERE BJ08.FileTrsmtStartHMS &gt;= #searchStart# ||'0000000000'
	        AND   BJ08.FileTrsmtStartHMS &lt;= #searchEnd# ||'9999999999'
	        AND   BJ08.BjobBzwkDstcd = BJ02.BjobBzwkDstcd
				<isNotEmpty prepend="AND" property="searchEaiBzwkDstcd">
				(  TRIM(BJ08.BjobBzwkDstcd) LIKE CONCAT( '%',CONCAT( UPPER(#searchEaiBzwkDstcd#) , '%') ) OR
					  BJ02.BjobBzwkName LIKE CONCAT( '%',CONCAT( UPPER(#searchEaiBzwkDstcd#) , '%') )   )
				</isNotEmpty>
	        GROUP BY
	                SUBSTR(FileTrsmtStartHMS, 1, 4)
	              , SUBSTR(FileTrsmtStartHMS, 5, 2)
	              , BJ08.BjobBzwkDstcd, BJ02.BjobBzwkName
	        ) TMP1
		GROUP BY StatcY, BjobBzwkDstcd, BjobBzwkName
  </statement>
</sqlMap>
