sql 中 foreach 中传入多个不同的参数问题

<!--查找某用户绑定的药物不良反应报告列表-->
<select id="selectSurveyListByUserProId" resultType="java.util.HashMap">
SELECT id AS `id`,time AS `time`,
usr_no AS `id_card_num`,
creat_usr_no AS `creat_usr_no`
FROM xy_survey
<where>
<foreach collection="list" index="index" item="userProIdmap" open="(" separator="," close=")">
<if test="userProIdmap != null">
<if test="userProIdmap.SerialNum != null and userProIdmap.SerialNum != ''"><!-- 注意and不能大写 -->
SerialNum = #{userProIdmap.SerialNum}
</if>
<if test="userProIdmap.company_id != null and userProIdmap.company_id != ''">
and company_id = #{userProIdmap.company_id}
</if>
<if test="userProIdmap.usr_no != null and userProIdmap.usr_no != ''">
and creat_usr_no = #{userProIdmap.usr_no}
</if>
</if>
</foreach>

</where>

GROUP BY id, time, usr_no, creat_usr_no
UNION
SELECT id AS `id`,
time AS `time`,
id_card_num AS `id_card_num`,
creat_usr_no AS `creat_usr_no`
FROM xy_survey_temp
<where>
<foreach collection="list" index="index" item="userProIdmap" open="(" separator="," close=")">
<if test="userProIdmap != null">
<if test="userProIdmap.SerialNum != null and userProIdmap.SerialNum != ''"><!-- 注意and不能大写 -->
SerialNum = #{userProIdmap.SerialNum}
</if>
<if test="userProIdmap.company_id != null and userProIdmap.company_id != ''">
and company_id = #{userProIdmap.company_id}
</if>
<if test="userProIdmap.usr_no != null and userProIdmap.usr_no != ''">
and creat_usr_no = #{userProIdmap.usr_no}
</if>
</if>
</foreach>

</where>
GROUP BY id, time, id_card_num, creat_usr_no
ORDER BY `time` DESC
</select>

 

<!-- 查询临时表获取主用户上传报告的患者数量,根据身份证号去除重复,参数 产品编号,公司id -->
<select id="findCountPersonNumXySurveyTemp" resultType="java.util.Map">
select id_card_num,SerialNum,company_id from xy_survey_temp where SerialNum in

<foreach collection="list" index="index" item="temps" open="(" separator="," close=")">
<if test="temps != null">
<if test="temps.SerialNum != null and temps.SerialNum !=''">
#{temps.SerialNum}
</if>

</if>
</foreach>
and company_id in
<foreach collection="list" index="index" item="temps" open="(" separator="," close=")">
<if test="temps != null">
<if test="temps.company_id != null and temps.company_id !=''">
#{temps.company_id}
</if>
</if>
</foreach>
group by id_card_num,SerialNum,company_id

</select>

posted @ 2019-12-19 19:10  红尘沙漏  阅读(1613)  评论(0编辑  收藏  举报