SELECT w.pjt_id pid,d.description pName,w.dept_id deptId,d1.departname pidName,w.yearmonth
<#if (wageEntity.attType)?? && wageEntity.attType != 0>
	,round(avg(w.unit_people_total)) peopleTotal,sum(w.wage_pay_total) wagePayTotal 
</#if>
<#if (wageEntity.attType)?? && wageEntity.attType == 0>
	,w.unit_people_total peopleTotal,w.wage_pay_total wagePayTotal
</#if>
from t_bus_depart_wage_statistics w
LEFT JOIN t_s_depart d
ON w.pjt_id = d.ID
LEFT JOIN t_s_depart d1
ON w.dept_id = d1.ID
where 1=1
<#if (wageEntity.attType)?? && wageEntity.attType == 2>
	and w.yearmonth like CONCAT('%', :wageEntity.attYear ,'%') 
</#if>
<#if (wageEntity.attType)?? && wageEntity.attType != 2>
	<#if ( wageEntity.yearMonthList )?? && wageEntity.yearMonthList ?size gt 0>
			and w.yearmonth in(
			<#list wageEntity.yearMonthList as item>        
			   '${item}'
			 <#if item_has_next>,</#if>
			 </#list>
			)
	</#if>
</#if>
<#if (wageEntity.pid)??>
		 and w.pjt_id =:wageEntity.pid
</#if>
<#if (wageEntity.attType)?? && wageEntity.attType != 0>
		  GROUP BY w.dept_id
</#if>

order by wagePayTotal desc