<#if (distributionEntity.attType)?? && distributionEntity.attType != 0>
SELECT yearmonth,deptId,departname,peopleNum,
IFNULL(CONVERT(peopleNum/totalNum*100,decimal(16,2)),0) proportion
FROM 
(
</#if>
SELECT cds.yearmonth yearmonth , cds.postid deptId, d.post_name departname , 
<#if (distributionEntity.attType)?? && distributionEntity.attType != 0>
	round(avg(people_num)) peopleNum,
	(
		SELECT SUM(total) peopletotal from  (
			SELECT round(avg(people_num)) total
			from t_bus_projpost_distribution_statistics cds
			LEFT JOIN t_bus_post d
			ON cds.postid = d.ID
			where 1=1
			and cds.pjt_id =:distributionEntity.pid
			<#if (distributionEntity.attType)?? && distributionEntity.attType == 2>
				and cds.yearmonth like CONCAT('%', :distributionEntity.attYear ,'%') 
			</#if>
			<#if (distributionEntity.attType)?? && distributionEntity.attType != 2>
				<#if ( distributionEntity.yearMonthList )?? && distributionEntity.yearMonthList ?size gt 0>
						and cds.yearmonth in(
						<#list distributionEntity.yearMonthList as item>        
						   '${item}'
						 <#if item_has_next>,</#if>
						 </#list>
						)
				</#if>	
			</#if>
			GROUP BY cds.postid
		) a	
	) totalNum
</#if>
<#if (distributionEntity.attType)?? && distributionEntity.attType == 0>
	cds.people_num peopleNum , cds.proportion proportion 
</#if>
from t_bus_projpost_distribution_statistics cds
LEFT JOIN t_bus_post d
ON cds.postid = d.ID
where 1=1
<#if (distributionEntity.attType)?? && distributionEntity.attType == 2>
	and cds.yearmonth like CONCAT('%', :distributionEntity.attYear ,'%') 
</#if>
<#if (distributionEntity.attType)?? && distributionEntity.attType != 2>
	<#if ( distributionEntity.yearMonthList )?? && distributionEntity.yearMonthList ?size gt 0>
			and cds.yearmonth in(
			<#list distributionEntity.yearMonthList as item>        
			   '${item}'
			 <#if item_has_next>,</#if>
			 </#list>
			)
	</#if>	
</#if>
<#if (distributionEntity.pid)??>
		 and cds.pjt_id =:distributionEntity.pid
</#if>
<#if (distributionEntity.attType)?? && distributionEntity.attType != 0>
		   GROUP BY cds.postid
		)a
</#if>
