mybatis写动态列语法应该这么写 前缀+变量 例如下面例子标红位置写,记住不能以这个CONCAT('a',#{index}),这种写法是当作字符串处理
<select id="getPersonCountByFormData" parameterType="map" resultType="int">
select count(*) from
(select a.projectid,a.pursuerid,a.personid,
<trim suffixOverrides=",">
<foreach item="item" index="index" collection="map.list">
max(case CONCAT('form',b.formid,'field',b.fieldid) when #{item.formfield} then data else '' end ) as a#{index},
</foreach>
</trim>
from iwrs_person a
join (SELECT *,fn_parseJson(if((rowid=104 or rowid=105 or rowid=106 or (rowid=108 and rowid <=111)),sdata,ldata),'value') as 'data' from iwrs_form_data
where projectid=#{map.projectid} and
<trim suffixOverrides="or">
<foreach item="item" index="index" collection="map.list">
(formid=#{item.formid} and fieldid=#{item.fieldid} ) or
</foreach>
</trim>
) b
on a.projectid=b.projectid and a.pursuerid=b.pursuerid and a.personid=b.personid
where a.projectid=#{map.projectid}
group by a.projectid,a.pursuerid,a.personid) c
<where>
c.projectid=#{map.projectid}
<trim prefixOverrides="or">
<foreach item="item" index="index" collection="map.list">
and a#{index}=#{item.val}
</foreach>
</trim>
</where>
</select>