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查询】的更多相关文章

  1. Mybatis中多表联查,查询出来的字段出现重名,造成数据异常的解决方法!

    在做一对多出现的问题,引发的思考:当数据库表中,主表的主键id和明细表的中的字段名相同时怎么办?Mybatis进行自动映射赋值的时候会不会出现异常?                      注意:M ...

  2. 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 ...

  3. Mysql联合查询UNION和UNION ALL的使用介绍

    UNION和UNION ALL的作用和语法 UNION 用于合并两个或多个 SELECT 语句的结果集,并消去表中任何重复行.UNION 内部的 SELECT 语句必须拥有相同数量的列,列也必须拥有相 ...

  4. [转]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 ...

  5. mysql 中合并查询结果union用法 or、in与union all 的查询效率

    mysql 中合并查询结果union用法 or.in与union all 的查询效率 (2016-05-09 11:18:23) 转载▼ 标签: mysql union or in 分类: mysql ...

  6. 【转】Mysql联合查询union和union all的使用介绍

    Mysql的联合查询命令UNION和UNION ALL,总结了使用语法和注意事项,以及学习例子和项目例子,需要的朋友可以参考下 一.UNION和UNION ALL的作用和语法 UNION 用于合... ...

  7. Hive学习之Union和子查询

    Union的语法格式如下: select_statement UNION ALL select_statement UNION ALL select_statement ... Union用于将多个S ...

  8. 【连接查询】mySql多表连接查询与union与union all用法

    1.准备两个表 表a: 结构: mysql> desc a; +-------+-------------+------+-----+---------+-------+ | Field | T ...

  9. SQL Server数据库Union和Union All查询出数据的区别?

    好久没有更新博客了,可能是最近比较忙,总是忽略了一些事情,今天查了做了一些数据分析的数据,突然感觉对Union和Union all有些不太理解了,可能是自己老了吧,就翻了一些资料,进行回忆和学习,趁着 ...

  10. Oracle 中 union 和union all 的简单使用说明

    1.刚刚工作不久,经常接触oracle,但是对oracle很多东西都不是很熟.今天我们来了解一下union和union all的简单使用说明.Union(union all): 指令的目的是将两个 S ...

随机推荐

  1. Java -- eclipse常用快捷键

  2. Mysql远程链接访问权限设置

    Host 'XXX' is not allowed to connect to this MySQL server 解决方案/如何开启MySQL的远程帐号 如何开启MySQL的远程帐号-1)首先以 r ...

  3. 机器学习(十四)— kMeans算法

    参考文献:https://www.jianshu.com/p/5314834f9f8e # -*- coding: utf-8 -*- """ Created on Mo ...

  4. Java之 将程序打包成jar包

    准备材料: 1.java文件: Helloworld.java package com.ray; public class HelloWorld{ public static void main(St ...

  5. PHP 常量、PHP 变量全解析(超全局变量、变量的8种数据类型等)

    常量特点 常量一旦被定义就无法更改或撤销定义. 常量名不需要开头的$ 与变量不同,常量贯穿整个脚本是自动全局的. 作用域不影响对常量的访问 常量值只能是字符串或数字 设置 PHP 常量 如需设置常量, ...

  6. C++之this指针与另一种“多态”

    一.引入 定义一个类的对象,首先系统已经给这个对象分配了空间,然后会调用构造函数(说明:假设存在构造函数--2010.9.5修正). 一个类有多个对象,当程序中调用对象的某个函数时,有可能要访问到这个 ...

  7. [冬令营模拟]wzj的题目#1

    T1 少膜一个,T3 暴力写挂 强势 rank1 -> rank2 一场比赛两道线段树分治,给力 T1 password 给你 m 个禁止字符串,求长度为 n 的所有字符串中至少包含这些禁止字符 ...

  8. 2488 绿豆蛙的归宿(拓扑+dp)

    488 绿豆蛙的归宿  时间限制: 1 s  空间限制: 64000 KB  题目等级 : 黄金 Gold 题解       题目描述 Description 随着新版百度空间的上线,Blog宠物绿豆 ...

  9. gulp之压缩图片

    //先全局安装gulp:npm install -g gulp //然后在项目根目录中安装gulp依赖:npm install --save-dev gulp //http://www.gulpjs. ...

  10. rsync 介绍和参数说明

    Rsync 介绍: 我们经常需要在不同目录或者服务器之间做文件同步和更新,Linux提供了很多内置命令可以使用比如scp等等,但是今天我们介绍一个更加强大的工具rsync.rsync 命令是一个远程同 ...