sql将两个查询结果拼接到一块,去掉重复,动态sql
- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
- <mapper namespace="org.springblade.desk.meeting.mapper.MeetingMapper">
- <delete id="deleteMeeting">
- delete from blade_meeting where meeting_code=#{meetingCode}
- </delete>
- <select id="getMeetingList" parameterType="org.springblade.desk.meeting.entity.MeetingEntity" resultType="org.springblade.desk.meeting.entity.MeetingEntity">
- select * from blade_meeting where tenant_id=#{tenantId}
- <if test="meetingDate != null and meetingDate !=''">
- and meeting_date=#{meetingDate}
- </if>
- <if test="startTime != null and startTime !='' or endTime != null and endTime !=''">
- and (
- ( concat(`meeting_date`,' ',`start_time`)<=#{startTime} and #{startTime}< concat(`meeting_date`,' ',`end_time`)) or
- (concat(`meeting_date`,' ',`start_time`)<=#{endTime} and #{endTime} < concat(`meeting_date`,' ',`end_time`))
- )
- </if>
- <if test="months != null and months !='' ">
- and (meeting_date like '%%${months}%%')
- </if>
- <if test="meetingAddress != null and meetingAddress !=''">
- and meeting_address =#{meetingAddress}
- </if>
- </select>
- <select id="getMyJoinMeetingPage" resultType="org.springblade.desk.meeting.entity.MeetingEntity">
- select * from (select a.* from blade_meeting a left join blade_meeting_person b on a.meeting_code=b.meeting_code
- where b.join_person_code=#{joinPersonCode}
- UNION
- select * from blade_meeting
- where meeting_launch_person_code=#{joinPersonCode}) t
- <where>
- <if test="meetingName != null">
- (meeting_name like '%%${meetingName}%%')
- </if>
- <if test="meetingDate != null">
- and (meeting_date like '%%${meetingDate}%%')
- </if>
- <if test="endDate != null and endDate !='' ">
- and meeting_date <= #{endDate}
- </if>
- <if test="noEndDate != null and noEndDate !='' ">
- and meeting_date >= #{noEndDate}
- </if>
- <if test="noEndTime != null and noEndTime !='' ">
- and concat(`meeting_date`,' ',`end_time`) > #{noEndTime}
- </if>
- <if test="endTime != null and endTime !='' ">
- and concat(`meeting_date`,' ',`end_time`) < #{endTime}
- </if>
- </where>
- order by meeting_date desc
- </select>
- </mapper>
- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
- <mapper namespace="org.springblade.desk.meeting.mapper.MeetingMapper">
- <delete id="deleteMeeting">
- delete from blade_meeting where meeting_code=#{meetingCode}
- </delete>
- <select id="getMeetingList" parameterType="org.springblade.desk.meeting.entity.MeetingEntity" resultType="org.springblade.desk.meeting.entity.MeetingEntity">
- select * from blade_meeting where tenant_id=#{tenantId}
- <if test="meetingDate != null and meetingDate !=''">
- and meeting_date=#{meetingDate}
- </if>
- <if test="startTime != null and startTime !='' or endTime != null and endTime !=''">
- and ( (#{startTime} between concat(`meeting_date`,' ',`start_time`) and concat(`meeting_date`,' ',`end_time`)) or
- (#{endTime} between concat(`meeting_date`,' ',`start_time`) and concat(`meeting_date`,' ',`end_time`))
- )
- </if>
- <if test="months != null and months !='' ">
- and (meeting_date like '%%${months}%%')
- </if>
- <if test="meetingAddress != null and meetingAddress !=''">
- and meeting_address =#{meetingAddress}
- </if>
- </select>
- <select id="getMyJoinMeetingPage" resultType="org.springblade.desk.meeting.entity.MeetingEntity">
- select * from (select a.* from blade_meeting a left join blade_meeting_person b on a.meeting_code=b.meeting_code
- where b.join_person_code=#{joinPersonCode}
- UNION
- select * from blade_meeting
- where meeting_launch_person_code=#{joinPersonCode}) t
- <where>
- <if test="meetingName != null">
- (meeting_name like '%%${meetingName}%%')
- </if>
- <if test="meetingDate != null">
- and (meeting_date like '%%${meetingDate}%%')
- </if>
- <if test="endDate != null and endDate !='' ">
- and meeting_date <= #{endDate}
- </if>
- <if test="noEndDate != null and noEndDate !='' ">
- and meeting_date >= #{noEndDate}
- </if>
- <if test="noEndTime != null and noEndTime !='' ">
- and concat(`meeting_date`,' ',`end_time`) > #{noEndTime}
- </if>
- <if test="endTime != null and endTime !='' ">
- and concat(`meeting_date`,' ',`end_time`) < #{endTime}
- </if>
- </where>
- order by meeting_date desc
- </select>
- </mapper>
- <select id="getMyJoinMeetingPage" resultType="org.springblade.desk.meeting.entity.MeetingEntity">
- select * from (select a.* from blade_meeting a left join blade_meeting_person b on a.meeting_code=b.meeting_code
- where b.join_person_code=#{joinPersonCode}
- UNION
- select * from blade_meeting
- where meeting_launch_person_code=#{joinPersonCode}) t
- <where>
- <if test="meetingName != null">
- (meeting_name like '%%${meetingName}%%')
- </if>
- <if test="meetingDate != null">
- and (meeting_date like '%%${meetingDate}%%')
- </if>
- <if test="endDate != null and endDate !='' ">
- and meeting_date <= #{endDate}
- </if>
- <if test="noEndDate != null and noEndDate !='' ">
- and meeting_date >= #{noEndDate}
- </if>
- <if test="noEndTime != null and noEndTime !='' ">
- and concat(`meeting_date`,' ',`end_time`) > #{noEndTime}
- </if>
- <if test="endTime != null and endTime !='' ">
- and concat(`meeting_date`,' ',`end_time`) < #{endTime}
- </if>
- </where>
- </select>
//
- concat(`meeting_date`,' ',`end_time`)将两个字段拼接到一块
sql将两个查询结果拼接到一块,去掉重复,动态sql的更多相关文章
- [moka同学笔记]YII2.0 判断签约状态,sql的两种查询方法
方法一: //判断签约状态 $signed = 0; $sql="SELECT * from usho_community_sign_record WHERE com_id=$r->i ...
- ms sql 根据表名查询 表中所有字段的属性值 sql语句
SELECT表名=case when a.colorder=1 then d.name else '' end,--表说明=case when a.colorder=1 then isnull(f.v ...
- mysql查询所有记录,并去掉重复的记录
select * from tablename group by name;如果是select * from tablename group by name,age;那么查询的是满足name和age都 ...
- 获取动态SQL查询语句返回值(sp_executesql)
在写存储过程时经常会遇到需要拼接SQL语句的情况,一般情况下仅仅是为了执行拼接后的语句使用exec(@sql)即可. 而今天的一个存储过程却需要获取动态SQL的查询结果. 需求描述:在某表中根据Id值 ...
- T-SQL动态查询(4)——动态SQL
接上文:T-SQL动态查询(3)--静态SQL 前言: 前面说了很多关于动态查询的内容,本文将介绍使用动态SQL解决动态查询的一些方法. 为什么使用动态SQL: 在很多项目中,动态SQL被广泛使用甚至 ...
- MyBatis学习总结(三)——多表关联查询与动态SQL
在上一章中我们学习了<MyBatis学习总结(二)——MyBatis核心配置文件与输入输出映射>,这一章主要是介绍一对一关联查询.一对多关联查询与动态SQL等内容. 一.多表关联查询 表与 ...
- sql server操作2:查询数据库语句大全【转】
注:以下操作均建立在上篇文章sql Server操作1的数据基础之上 一.实验目的 熟悉SQL语句的基本使用方法,学习如何编写SQL语句来实现查询 二.实验内容和要求 使用SQL查询分析器查询数据,练 ...
- SQL SERVER中XML查询:FOR XML指定PATH
SQL SERVER中XML查询:FOR XML指定PATH 前言 在SQL SERVER中,XML查询能够指定RAW,AUTO,EXPLICIT,PATH.本文用一些实例介绍SQL SERVER中指 ...
- Sql Server 存储过程中查询数据无法使用 Union(All)
原文:Sql Server 存储过程中查询数据无法使用 Union(All) 微软Sql Server数据库中,书写存储过程时,关于查询数据,无法使用Union(All)关联多个查询. 1.先看一段正 ...
随机推荐
- 网络 华为 ensp 命令
VLAN 端口有三种模式:access,hybrid,trunk. Access类型端口:只能属于1个VLAN,且该端口不打tag,一般用于连接计算机端口: Trunk类型端口:可以允许多个VLAN通 ...
- C语言实现聊天室(windows版本)
来源:微信公众号「编程学习基地」 目录 C语言聊天室 运行效果 分析设计 多线程 线程的同步 服务端设计 遇到的问题 C语言聊天室 基于 tcp 实现群聊功能,本项目设计是在windows环境下基于套 ...
- CentOS下构建Shell简易分发系统
bash经典收集 经典收集1 for f in `(cd .; find suite -type f | grep -v SCCS)`; \ do \ d=/usr/local/mysql/mysql ...
- bootstrap火速布局"企业级"页面
套娃 .container(两边有margin)/container-fluid(无) 大盒,写一个当爹就行 .row 行 .col 列 列中可再嵌套行和列 大小 把屏幕分成十二列看 .col-(xs ...
- LeetCode 047 Permutations II
题目要求:Permutations II Given a collection of numbers that might contain duplicates, return all possibl ...
- python 二维数组赋值问题
[[]]是一个含有一个空列表元素的列表,所以[[]]*3表示3个指向这个空列表元素的引用, 修改任何一个元素都会改变整个列表 所以需要用另外一种方式进行创建多维数组,以免浅拷贝 >>> ...
- 关于javaSMTP协议发邮件你必须知道的知识点
1.阅读官方吐槽 Note also that THERE IS NOT SUFFICIENT DOCUMENTATION HERE TO USE THESE FEATURES!!! You will ...
- 什么是Python生成器?与迭代器的关系是什么?
生成器是一个特殊的迭代器,它保存的是算法,每次调用next()或send()就计算出下一个元素的值,直到计算出最后一个元素,没有更多的元素时,抛出StopIteration.生成器有两种类型,一种是生 ...
- PyQt(Python+Qt)学习随笔:QTreeWidget树型部件中的QTreeWidgetItem项构造方法
老猿Python博文目录 专栏:使用PyQt开发图形界面Python应用 老猿Python博客地址 QTreeWidget树型部件的项是单独的类对象,这个类就是QTreeWidgetItem. QTr ...
- 第11.23节 Python 中re模块的搜索替换功能:sub及subn函数
一. 引言 在<第11.3节 Python正则表达式搜索支持函数search.match.fullmatch.findall.finditer>重点介绍了几个搜索函数,除了搜索,re模块也 ...