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>
sql 中 foreach 中传入多个不同的参数问题的更多相关文章
- php中foreach中使用&的办法
刚开始在使用foreach时候一直不理解为什么要使用& 后来发现在给一个数组里面添加数据时候很好用 <?phpheader("Content-Type:text/html;ch ...
- mybatis中foreach的用法(转)
foreach一共有三种类型,分别为List,[](array),Map三种. foreach属性 属性 描述 item 循环体中的具体对象.支持属性的点路径访问,如item.age,item.inf ...
- 谈一下思考,关于mybatis中<foreach collection="list">中list得来的原因 没看到官方说明
<foreach> 是在sql语句中进行多个id查询 时用到的,因为mybatis代替jdbc和hibernate, 使用 在xml文件中编写sql语句,这是一个标签文件.然后在 dao层 ...
- mybatis 中 foreach 的性能问题及调优
1.mybatis中最初的sql语句 SELECT 参数1, 参数2, 参数3 FROM 表 WHERE 条件参数1 in <foreach item="item" inde ...
- foreach中的collection
foreach中collection的三种用法 https://www.cnblogs.com/xiemingjun/p/9800999.html foreach的主要用在构建in条件中,它可以在SQ ...
- mybatis中foreach使用方法
作者:学无先后 达者为先 作者:偶尔记一下 foreach一共有三种类型,分别为List,[](array),Map三种. 下面表格是我总结的各个属性的用途和注意点. foreach属性 属性 描述 ...
- SQL Server 存储过程中处理多个查询条件的几种常见写法分析,我们该用那种写法
本文出处: http://www.cnblogs.com/wy123/p/5958047.html 最近发现还有不少做开发的小伙伴,在写存储过程的时候,在参考已有的不同的写法时,往往很迷茫,不知道各种 ...
- SQL Server存储过程中使用表值作为输入参数示例
这篇文章主要介绍了SQL Server存储过程中使用表值作为输入参数示例,使用表值参数,可以不必创建临时表或许多参数,即可向 Transact-SQL 语句或例程(如存储过程或函数)发送多行数据,这样 ...
- SQL Server 2008中新增的 1.变更数据捕获(CDC) 和 2.更改跟踪
概述 1.变更数据捕获(CDC) 每一次的数据操作都会记录下来 2.更改跟踪 只会记录最新一条记录 以上两种的区别: http://blog.csdn.n ...
随机推荐
- xios封装
封装的意义 1.提高代码可读性2.提高代码可维护性3.减少代码书写 封装 import axios from 'axios' axios.defaults.baseURL = 'http://127. ...
- web自动化-绕过登录
两个方法: 1.常用的方法: 第一种方法是登录后查看网站的 cookie,请求 url 的时候把 cookie 带上(缺点是:cookie有时间限制.优点:简单,方便) 2.添加cookies的方式: ...
- Spring Boot 使用 XXL-JOB
一.配置部署调度中心 1.1 下载源码 https://github.com/xuxueli/xxl-job 1.2 数据库初始化 执行 /xxl-job/doc/db/tables_xxl_job. ...
- k8s 部署 Java 项目
前几天安装了 k8s 并测试了自动伸缩功能(HPA),今天来部署一个简单的 Java 应用到 k8s. 开始之前需要先安装一下 ingress 插件.ingress 作为 k8s 的流量入口,有多种实 ...
- Markdown实用教程
Markdown 是用来编写结构化文档的一种纯文本格式,它使我们在双手不离开键盘的情况下,可以对文本进行一定程度的格式排版.markdown语法是通用的,很多写作平台都是支持markdown的,比如简 ...
- 关于Python中中文文本文件使用二进制方式读取后的解码UnicodeDecodeError问题
最近老猿在进行文件操作的验证测试,发现对于中文文本文件如果使用二进制方式打开,返回的类型是bytes,如果要转换成可读的字符串信息需要进行解码.可是老猿使用decode()或decode(" ...
- PyQt(Python+Qt)学习随笔:Qt Designer中部件的geometry几何属性
geometry属性保存部件相对于其父级对象的位置和大小,Qt实际上是以一个长方形来表示部件的位置和大小的,包括左上角的坐标位置.长度和宽带. 当部件的geometry调整时,部件如果可见将立即接收m ...
- CSS基础-列表
列表字体和间距 当创建样式列表时,需要调整样式,使其保持与周围元素相同的垂直间距和相互间的水平间距. 示例代码 /* 基准样式 */ html { font-family: Helvetica, ...
- CSP-S2020复赛游记
[本文经过删改] 前一个月 没做什么 NOIP 的题,感觉这些题对我这个做黄题封顶的人不是很友好. 前一天 考了场模拟赛,全场最低分 89,感觉信心满满. 退役那天 到了 XJ,发现没人可以面基,想着 ...
- sublime text3 将tab转换为2个或4个空格,并显示空格
有很多软件并不能解析tab,而往往有的程序员喜欢使用tab键进行对齐,sublime text可以很好的解决这个问题. 首先打开sublime text,点击preferences->setti ...