【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 ...
随机推荐
- 关于ansible变量的一个问题
ansible-playbook 使用with_items 时 items中 如果有变量 {} 外面可以用 “” items中 如果都是固定值,没有用到变量,{}最外面不要加 “” ,不然报错,mmp
- 记录quick cocos2d-x3.2升级至cocos2d-x3.8
目前为止,quickcocos2d-x没有3.8版本,想用3.8又想用quick,所以只能自己升级了,自己先记录下,防止忘记. cocos2d-x3.8里面有quick framework,而simu ...
- html怎样可是使文本框内容不可修改
html怎样可是使文本框内容不可修改 <input type="text" readonly="readonly" onfocus="alert ...
- django 实现分页功能
分页效果: 视图代码: # -*- coding: utf-8 -*- from django.shortcuts import render,get_object_or_404 from djang ...
- 如何让DIV可编辑、可拖动
1.可编辑: <div id="move" contentEditable="true">可编辑</div> 设置contentEdit ...
- 一个类的类类型是Class类的实例,即类的字节码
new 是静态加载类,编译时期加载.一遍功能性的类 需要动态加载
- 【leetcode刷题笔记】Best Time to Buy and Sell Stock III
Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...
- LeetCode Majority Element I
原题链接在这里:https://leetcode.com/problems/majority-element/ 题目: Given an array of size n, find the major ...
- Android的Notification相关设置
Android手机:三星Galaxy S6 Android版本:Android 7.0 Android系统自带的本地通知会从顶部Pop下来,用来提示用户有新的消息,然后在Notification栏中停 ...
- android开发之Bitmap 、byte[] 、 Drawable之间的相互转换
一.相关概念 1.Drawable就是一个可画的对象,其可能是一张位图(BitmapDrawable),也可能是一个图形(ShapeDrawable),还有可能是一个图层(LayerDrawable) ...