반응형

 

<select id="selectByCareerYear" resultType="HashMap">
	select user_career_year || '년'
			,count(user_career_year) || '명'
				from(select 
					 trunc(months_between(sysdate,user_comp_enter)/12) user_career_year 
					 from user_info) 
				where not user_career_year is NULL 
				group by user_career_year 
				order by user_career_year desc
</select>

셀렉트 결과를... Developer에서 봤을때 처럼..

원하는 모양 : Hashmap으로 key="9년" , value="1명"

{COUNT(USER_CAREER_YEAR)||'명'=1명, USER_CAREER_YEAR||'년'=9년}

 

keySet() 으로 확인해보니 key는  [COUNT(USER_CAREER_YEAR)||'명', USER_CAREER_YEAR||'년'] 이고

values() 로 확인해보니 values는 [1명,9년] 

이렇게 뜨는데... 

그럼 쿼리문에서 이름을 바꾸자..

as로 alias를 명명했다

<select id="selectByCareerYear" resultType="HashMap">
	select user_career_year || '년' as year
			,count(user_career_year) || '명' as count
				from(select 
					trunc(months_between(sysdate,user_comp_enter)/12) user_career_year 
					from user_info) 
				where not user_career_year is NULL 
				group by user_career_year 
				order by user_career_year desc
</select>

keySet이 year과 count가 되었다. 

반응형

+ Recent posts