模糊查询和排序后合并查询结果集
2015-11-16 17:08
253 查看
今天需要做一个查询,当天时间按时间降序排列排在最前面,然后是其他的按时间降序排列排在当天的时间后面。
select * from
( select * from Table
where time like '2015-11-16%'
order by time desc ) a
union all select * from
(select * from Table
where id not in
( select Table.id from Table
where time like '2015-11-12%')
order by time desc ) b
limit 0,20
必须外面包一层,直接两个结果集 union 发现正常的在上面,到期的在下面,但是各自内部是无序的,也就是说union的时候是没有order by做的union,
内部的order by没有生效, 包了一层应该是产生了临时中间表,次序便固定了。
select * from
( select * from Table
where time like '2015-11-16%'
order by time desc ) a
union all select * from
(select * from Table
where id not in
( select Table.id from Table
where time like '2015-11-12%')
order by time desc ) b
limit 0,20
必须外面包一层,直接两个结果集 union 发现正常的在上面,到期的在下面,但是各自内部是无序的,也就是说union的时候是没有order by做的union,
内部的order by没有生效, 包了一层应该是产生了临时中间表,次序便固定了。
相关文章推荐
- asp.net mvc webconfig配置文件操作
- 第十二周项目一 图基本算法库
- 第12周项目1——图基本算法库
- 深入浅出Tabhost+简单入门Demo
- 磁盘及文件系统的管理
- 第十一周实践项目1(2)--二叉树的构造
- 面向对象OOP 03 类常量
- Android开发工具常用快捷键大全
- 使用Tiny作为工具进行图片压缩
- 动画效果,几张图片围绕一点旋转
- HDU-2003 求绝对值
- nyoj168 房间安排问题
- 4、传统三层架构与DDD分层架构
- linux查询cpu核心数
- 数据结构之自建算法库——图及其存储结构(邻接矩阵、邻接表)
- 第十二周--利用遍历思想求解图问题(DFS)
- 关于Ajax ,jQuery以及jQuery Ajax 编程 (五)
- 需求分析过程中 项目里可能需要的技术点记录
- 第九周实践项目~广义表算法库及应用
- Mac OS X 使用手册 by STP