zoukankan      html  css  js  c++  java
  • 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>

  • 相关阅读:
    day5-Python学习笔记(九)json数据类型
    day5-Python学习笔记(八)内置函数
    day4-Python学习笔记(七)函数与模块
    day4-Python学习笔记(六)监控日志,集合数据类型
    day4-Python学习笔记(五)文件读写,文件内容修改
    day3-python学习笔记(四)字符串方法
    day3-python学习笔记(三)字典、元组
    day3-python学习笔记(二)list(数组)
    变量
    网络编程
  • 原文地址:https://www.cnblogs.com/xianz666/p/12069605.html
Copyright © 2011-2022 走看看