<!--查找某用户绑定的药物不良反应报告列表-->
<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>

sql 中 foreach 中传入多个不同的参数问题的更多相关文章

  1. php中foreach中使用&的办法

    刚开始在使用foreach时候一直不理解为什么要使用& 后来发现在给一个数组里面添加数据时候很好用 <?phpheader("Content-Type:text/html;ch ...

  2. mybatis中foreach的用法(转)

    foreach一共有三种类型,分别为List,[](array),Map三种. foreach属性 属性 描述 item 循环体中的具体对象.支持属性的点路径访问,如item.age,item.inf ...

  3. 谈一下思考,关于mybatis中<foreach collection="list">中list得来的原因 没看到官方说明

    <foreach> 是在sql语句中进行多个id查询 时用到的,因为mybatis代替jdbc和hibernate, 使用 在xml文件中编写sql语句,这是一个标签文件.然后在 dao层 ...

  4. mybatis 中 foreach 的性能问题及调优

    1.mybatis中最初的sql语句 SELECT 参数1, 参数2, 参数3 FROM 表 WHERE 条件参数1 in <foreach item="item" inde ...

  5. foreach中的collection

    foreach中collection的三种用法 https://www.cnblogs.com/xiemingjun/p/9800999.html foreach的主要用在构建in条件中,它可以在SQ ...

  6. mybatis中foreach使用方法

    作者:学无先后 达者为先 作者:偶尔记一下 foreach一共有三种类型,分别为List,[](array),Map三种. 下面表格是我总结的各个属性的用途和注意点. foreach属性 属性 描述 ...

  7. SQL Server 存储过程中处理多个查询条件的几种常见写法分析,我们该用那种写法

    本文出处: http://www.cnblogs.com/wy123/p/5958047.html 最近发现还有不少做开发的小伙伴,在写存储过程的时候,在参考已有的不同的写法时,往往很迷茫,不知道各种 ...

  8. SQL Server存储过程中使用表值作为输入参数示例

    这篇文章主要介绍了SQL Server存储过程中使用表值作为输入参数示例,使用表值参数,可以不必创建临时表或许多参数,即可向 Transact-SQL 语句或例程(如存储过程或函数)发送多行数据,这样 ...

  9. SQL Server 2008中新增的 1.变更数据捕获(CDC) 和 2.更改跟踪

    概述 1.变更数据捕获(CDC)        每一次的数据操作都会记录下来 2.更改跟踪       只会记录最新一条记录   以上两种的区别:         http://blog.csdn.n ...

随机推荐

  1. Linux Tomcat安装篇(daemon运行,开机自启动)

    目录 前言 作为一个Java后端开发者,tomcat想必是最最最熟悉的一个开发组件了,tomcat环境的搭建部署都十分简单.安装部署只需要两步,第一步下载,第二步解压,这样一个基础的tomcat环境就 ...

  2. 使用github actions 完成一些自动化工作

    github actions 是什么? github actions是github的持续集成及自动化工作流服务,使用起来都比较方便.大部分github actions都可以在https://githu ...

  3. 浅谈JAVA servlet

    1.servlet是什么? servlet的本质是接口,接口就是一种规范.我们来看一下servlet接口中都有哪些函数: 图片来源:https://www.cnblogs.com/whgk/p/639 ...

  4. dubbo源码学习(一)dubbo容器启动流程简略分析

    最近在学习dubbo,dubbo的使用感觉非常的简单,方便,基于Spring的容器加载配置文件就能直接搭建起dubbo,之前学习中没有养成记笔记的习惯,时间一久就容易忘记,后期的复习又需要话费较长的时 ...

  5. 问题:PyCharm调试方法smart step into的用途

    smart step into为智能单步跟踪,当一行代码中有多个函数,想进入其中一个函数调测其他函数不进入调测时,使用该功能可以让调试人员选择进入的函数.如: 就可以选择需要调试进入的函数而其他两个函 ...

  6. Python基础知识学习随笔

    Python学习随笔:PyCharm的错误检测使用及调整配置减少错误数量 Python学习随笔:获取当前主机名和用户名的方法 博客地址:https://blog.csdn.net/LaoYuanPyt ...

  7. 【软件测试部署基础】yarn的认识

    1. yarn是什么 Yarn 是 Facebook, Google, Exponent 和 Tilde 开发的一款新的 JavaScript 包管理工具.其主要是为了弥补 npm 的一些少量的缺陷而 ...

  8. 中间件面试专题:RabbitMQ高频面试问题

  9. 【SDOI2017】天才黑客(前后缀优化建图 & 最短路)

    Description 给定一张有向图,\(n\) 个点,\(m\) 条边.第 \(i\) 条边上有一个边权 \(c_i\),以及一个字符串 \(s_i\). 其中字符串 \(s_1, s_2, \c ...

  10. uniapp计算属性的使用

    计算属性,也可称为动态属性,在uniapp中有两种写法: 第一种:直接返回一个计算的值,该计算属性为函数类型 computed:{ kh_score(){ var list = this.taskLi ...