괴발개발/Spring Framework

DB_최고MAX,최저MIN 카운트COUNT 구하기

moonday 2021. 10. 1. 11:42

MYSQL

    select max(count) as consulting_countMax, min(count) as consulting_countMin from 
    (select student_consulting_id, count(student_consulting_id) as count from consulting		
	where consulting_deletion="N" and consulting_date like concat(2021,'%')
    group by student_consulting_id) as count
			join student on student_id = student_consulting_id
				where teacher_student_id = '49' and student_deletion="N";

 

MAPPER

	<select id="getCompareConsulting" resultType="kr.portfolio.forfree.vo.StudentVO">
		select max(count) as consulting_countMax, min(count) as consulting_countMin from 
    (select student_consulting_id, count(student_consulting_id) as count from consulting		
		where consulting_deletion="N" and consulting_date like concat(#{thisYear},"%")
    group by student_consulting_id) as count
				join student on student_id = student_consulting_id
				where teacher_student_id = #{teacher_id} and student_deletion="N";
	</select>