package com.dbs.mplus.service.admin.agg.repository.oracle;

import com.dbs.mplus.framework.template.MPlusQuery;

/**
 * 사용자 정보 통계를 위한 임시테이블용 질의 
 * @author aple
 *
 */
public class AggUserTmpMPlusQuery extends MPlusQuery { 

	@Override 
	public String getQueryForInsert() {
		return "INSERT INTO MP_AGG_USER_TMP(AGE_ORDER, POSTNO_VALUE) " + 
				"VALUES(:ageOrder, :postnoValue)";
	}
	
	@Override 
	public String getQueryForDelete() {
		return "DELETE FROM MP_AGG_USER_TMP"; 
	}
	
	/**
	 * 연령별 통계 
	 * @return
	 */
	public String findByAgeOrder() { 
		return "SELECT AGE_ORDER, COUNT(1) AS DATA_CNT " + 
				" FROM MP_AGG_USER_TMP " + 
				" GROUP BY AGE_ORDER " + 
				" ORDER BY AGE_ORDER ASC"; 
	}
	
	/**
	 * 우편번호별 통계 
	 * @return
	 */
	public String findByPostno() { 
		return "SELECT T.POSTNO_VALUE, COUNT(1) AS DATA_CNT  " + 
				" FROM ( " + 
				" 	SELECT  " + 
				"		(SELECT SI_VALUE FROM MP_ZIPCODE WHERE SI_ID=POSTNO_VALUE AND ROWNUM<=1) AS POSTNO_VALUE " +
				"	FROM MP_AGG_USER_TMP " +
				" ) T " + 
				" GROUP BY T.POSTNO_VALUE  "; 
	}
}
