【mybatis 如何写union和union查询】
select d.* from (
select a.CheckType,b.UserName,a.CheckNumber, a.PayName ,a.PayBank,a.PayBankNumber,a.PayMoney, a.CheckTime,a.CheckState ,a.PayFee
from deal_check a , accounts_users b
where a.userid=b.userid and 1=1
and DATE_FORMAT(a.CheckTime,'%Y-%m-%d') >= '2017-04-01'
and DATE_FORMAT(a.CheckTime,'%Y-%m-%d') <= '2017-04-10'
and CheckState=3
order by a.CheckTime desc limit 0,10 ) d
union
select e.* from (
select a.CheckType,b.UserName,a.CheckNumber, a.PayName ,a.PayBank,a.PayBankNumber,a.PayMoney, a.CheckTime,a.CheckState ,a.PayFee
from deal_check a , agent b
where a.userid=b.userid and 1=1
and DATE_FORMAT(a.CheckTime,'%Y-%m-%d') >= '2017-04-01'
and DATE_FORMAT(a.CheckTime,'%Y-%m-%d') <= '2017-04-10'
and CheckState=3
order by a.CheckTime desc limit 0,10
) e
=======================================================================
<select id="selectDealshow" resultMap="BaseResultMap">
select c.* from (
select a.CheckType,b.UserName,a.CheckNumber, a.PayName
,a.PayBank,a.PayBankNumber,a.PayMoney,
a.CheckTime,a.CheckState
,a.PayFee from deal_check a , accounts_users b where a.userid=b.userid
and 1=1
<if test="userName !=null and userName !=''">
and userName=#{userName}
</if>
<if test="start !=null and start !=''">
and DATE_FORMAT(a.CheckTime,'%Y-%m-%d')<![CDATA[>=]]>#{start}
</if>
<if test="end !=null and end !=''">
and DATE_FORMAT(a.CheckTime,'%Y-%m-%d')<![CDATA[<=]]>#{end}
</if>
<if test="checkType !=null and checkType !=0">
and CheckType=#{checkType}
</if>
<if test="CheckState !=null and CheckState !=0">
and CheckState=#{CheckState}
</if>
<if test="CheckState ==null or CheckState ==0">
and CheckState in (-1,1,2,3)
</if>
<if test="payName !=null and payName !=''">
and a.PayName=#{payName}
</if>
<if test="payBankNumber !=null and payBankNumber !=''">
and PayBankNumber=#{payBankNumber}
</if>
<if test="orderNumber !=null and orderNumber !=''">
and CheckNumber=#{orderNumber}
</if>
order by a.CheckTime desc limit ${target},${pageSize}
) c
union
select d.* from (
select a.CheckType,b.UserName,a.CheckNumber, a.PayName
,a.PayBank,a.PayBankNumber,a.PayMoney,
a.CheckTime,a.CheckState
,a.PayFee from deal_check a , agent b where a.userid=b.userid
and 1=1
<if test="userName !=null and userName !=''">
and userName=#{userName}
</if>
<if test="start !=null and start !=''">
and DATE_FORMAT(a.CheckTime,'%Y-%m-%d')<![CDATA[>=]]>#{start}
</if>
<if test="end !=null and end !=''">
and DATE_FORMAT(a.CheckTime,'%Y-%m-%d')<![CDATA[<=]]>#{end}
</if>
<if test="checkType !=null and checkType !=0">
and CheckType=#{checkType}
</if>
<if test="CheckState !=null and CheckState !=0">
and CheckState=#{CheckState}
</if>
<if test="CheckState ==null or CheckState ==0">
and CheckState in (-1,1,2,3)
</if>
<if test="payName !=null and payName !=''">
and a.PayName=#{payName}
</if>
<if test="payBankNumber !=null and payBankNumber !=''">
and PayBankNumber=#{payBankNumber}
</if>
<if test="orderNumber !=null and orderNumber !=''">
and CheckNumber=#{orderNumber}
</if>
order by a.CheckTime desc limit ${target},${pageSize}
) d
</select>
【mybatis 如何写union和union查询】的更多相关文章
- Mybatis中多表联查,查询出来的字段出现重名,造成数据异常的解决方法!
在做一对多出现的问题,引发的思考:当数据库表中,主表的主键id和明细表的中的字段名相同时怎么办?Mybatis进行自动映射赋值的时候会不会出现异常? 注意:M ...
- C#Linq中的Union All/Union/Intersect和Top/Bottom和Paging和SqlMethods,skip,take,takewhile,skipwhile,编译查询等
我们继续讲解LINQ to SQL语句,这篇我们来讨论Union All/Union/Intersect操作和Top/Bottom操作和Paging操作和SqlMethods操作 . Union Al ...
- Mysql联合查询UNION和UNION ALL的使用介绍
UNION和UNION ALL的作用和语法 UNION 用于合并两个或多个 SELECT 语句的结果集,并消去表中任何重复行.UNION 内部的 SELECT 语句必须拥有相同数量的列,列也必须拥有相 ...
- [转]C#Linq中的Union All/Union/Intersect和Top/Bottom和Paging和SqlMethods,skip,take,takewhile,skipwhile,编译查询等
本文转自:http://www.cnblogs.com/suizhikuo/p/3791799.html 我们继续讲解LINQ to SQL语句,这篇我们来讨论Union All/Union/Inte ...
- mysql 中合并查询结果union用法 or、in与union all 的查询效率
mysql 中合并查询结果union用法 or.in与union all 的查询效率 (2016-05-09 11:18:23) 转载▼ 标签: mysql union or in 分类: mysql ...
- 【转】Mysql联合查询union和union all的使用介绍
Mysql的联合查询命令UNION和UNION ALL,总结了使用语法和注意事项,以及学习例子和项目例子,需要的朋友可以参考下 一.UNION和UNION ALL的作用和语法 UNION 用于合... ...
- Hive学习之Union和子查询
Union的语法格式如下: select_statement UNION ALL select_statement UNION ALL select_statement ... Union用于将多个S ...
- 【连接查询】mySql多表连接查询与union与union all用法
1.准备两个表 表a: 结构: mysql> desc a; +-------+-------------+------+-----+---------+-------+ | Field | T ...
- SQL Server数据库Union和Union All查询出数据的区别?
好久没有更新博客了,可能是最近比较忙,总是忽略了一些事情,今天查了做了一些数据分析的数据,突然感觉对Union和Union all有些不太理解了,可能是自己老了吧,就翻了一些资料,进行回忆和学习,趁着 ...
- Oracle 中 union 和union all 的简单使用说明
1.刚刚工作不久,经常接触oracle,但是对oracle很多东西都不是很熟.今天我们来了解一下union和union all的简单使用说明.Union(union all): 指令的目的是将两个 S ...
随机推荐
- Python习题-输出一个字符串中最长的子字符串及其长度
描述:有个字符串$sd1#111$svda123!!!221&eSSDSDG,包含特殊字符.数字和字母,输出最长的子字符串和他的长度#例如上面的字符串包含数字字母的字符串是svda123,长度 ...
- 常规DLL与扩展DLL区别
1.常规DLL可以被各种程序(python,VB等)调用,扩展DLL只能被MFC程序调用.提供给外部使用的控件类只能用扩展DLL. 2.扩展DLL的入口函数是DllMain(),而常规DLL入口是继承 ...
- java try中包含return语句,finally中的return语句返回顺序
//结论: finally 中的代码比 return 和 break 语句后执行 public static void main(String[] args) { int x=new Test.tes ...
- JAVA堆内存和栈内存初步了解
一.堆内存和栈内存 程序运行时内存分配有三种:静态存储分配,栈式存储分配,堆式存储分配 1.静态存储分配: 在程序编译时就可以确定数据目标在运行时所需要的内存,因此在编译时就为其分配固定大小的内存. ...
- Linux-解决putty无法直接使用root用户远程登录linux主机的问题
问题描述: 有时,在使用putty连接远程linux主机时会发现,无法直接使用root登录, 但是可以使用其他用户登录,然后切换至root用户. 解决办法: 1.修改配置文件 vi /etc/ssh/ ...
- stl_tree.h
stl_tree.h G++ ,cygnus\cygwin-b20\include\g++\stl_tree.h 完整列表 /* * * Copyright (c) 1996,1997 * Silic ...
- SQL Server 2008可以安装在win7 64位的系统上吗?
可以安装的.SQL 支持32和64位.安装时它自动选择的.下载时注意是完整安装包. SQLFULL_CHS 2008.iso大小:3.28G 已经过百度安全检测,放心下载
- ffmpeg混音(将多个声音合成一个)命令
ffmpeg命令中可以使用filter amix实现这个功能. 官方文档 http://ffmpeg.org/ffmpeg-filters.html 6.8 amix Mixes multiple a ...
- ffmpeg解码RTSP/TCP视频流H.264(QT界面显示视频画面)
源码下载地址: http://download.csdn.net/detail/liukang325/9489952 我用的ffmpeg版本为 ffmpeg-2.1.8.tar.bz2 版本低了恐怕有 ...
- [POI 2018] Plan Metra
[题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=5100 [算法] 首先分两类考虑 : 1. 1 -> N的路径不经过其它节点 , ...