<select id="elecpowerExchangeList" resultType="pd" parameterType="pd">
select t1.sending_name,t1.receiving_name
<foreach collection="years" item="year" open="," separator=",">
(select t2.electric_max from <include refid="tableName"/>t2
where t2.time_year=#{year} and t2.sending_name=t1.sending_name and t2.receiving_name=t1.receiving_name)as max_${year},
(select t2.electric_per_year from <include refid="tableName"/>t2
where t2.time_year=#{year} and t2.sending_name=t1.sending_name and t2.receiving_name=t1.receiving_name)as sum_${year}
</foreach>
from <include refid="tableName"/>t1
group by t1.sending_name,t1.receiving_name
</select>
查询的结果的字段名 如果year=2018时候 字段名是max_2018,sum_2018