• 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>

  • 相关阅读:
    解决HbuilderX乱码问题
    IDEA
    关于Git开发的一些注意事项
    postgresql
    启动新拉取项目流程
    关于能发布但无法打包的问题
    关于人脸感知设备(类似门禁考勤设备)搜索添加显示成功但却添加不上的问题
    在GitLab上创建项目并上传初始文件
    中控标替换成白标开发
    工厂模式
  • 原文地址:https://www.cnblogs.com/xianz666/p/12069605.html
Copyright © 2020-2023  润新知