SELECT e.* <#if (userEntity.attType)?? && userEntity.attType != 0> ,( SELECT earlymonth_total from t_bus_dept_user_statistics pus WHERE pus.pjt_id=e.pid and pus.dept_id = e.deptId and pus.yearmonth=e.minyearmonth ) earlyMonthTotal ,( SELECT endmonth_total from t_bus_dept_user_statistics pus WHERE pus.pjt_id=e.pid and pus.dept_id = e.deptId and pus.yearmonth=e.maxyearmonth ) endMonthTotal FROM ( SELECT u.pjt_id pid,d.description pName,u.dept_id deptId,d1.departname pidName,u.yearmonth <#if (userEntity.attType)?? && userEntity.attType != 0> ,MAX(yearmonth) maxyearmonth,MIN(yearmonth) minyearmonth ,sum(u.entry_total) entryTotal,sum(u.leave_total) leaveTotal ,convert(avg(u.flow_proportion),decimal(10,2)) flowProportion <#if (userEntity.attType)?? && userEntity.attType == 0> ,u.earlymonth_total earlyMonthTotal ,u.endmonth_total endMonthTotal ,u.entry_total entryTotal,u.leave_total leaveTotal ,u.flow_proportion flowProportion from t_bus_dept_user_statistics u LEFT JOIN t_s_depart d ON u.pjt_id = d.ID LEFT JOIN t_s_depart d1 ON u.dept_id = d1.ID where 1=1 <#if (userEntity.attType)?? && userEntity.attType == 2> and u.yearmonth like CONCAT('%', :userEntity.attYear ,'%') <#if (userEntity.attType)?? && userEntity.attType != 2> <#if ( userEntity.yearMonthList )?? && userEntity.yearMonthList ?size gt 0> and u.yearmonth in( <#list userEntity.yearMonthList as item> '${item}' <#if item_has_next>, ) <#if (userEntity.pid)??> and u.pjt_id =:userEntity.pid GROUP BY u.dept_id ) e order by flowProportion desc