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>

  • 相关阅读:
    CSS 中的字体兼容写法:用CSS为英文和中文字体分别设置不同的字体
    利用vue-cropper做的关于图片裁剪、压缩、上传、预览等做的一个公共组件
    解决浏览器拦截弹出窗口问题
    详解Vue中的nextTick
    vue里ref ($refs)用法
    vue组件的hover事件模拟、给第三方组件绑定事件不生效问题
    JS实现千分位
    JS实现异步编程的4种方法
    Cas_个人理解
    zabbix_监控_邮件预警
  • 原文地址:https://www.cnblogs.com/xianz666/p/12069605.html
Copyright © 2011-2022 走看看