zoukankan      html  css  js  c++  java
  • 模糊查询和排序后合并查询结果集

    今天需要做一个查询,当天时间按时间降序排列排在最前面,然后是其他的按时间降序排列排在当天的时间后面。

    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没有生效, 包了一层应该是产生了临时中间表,次序便固定了。

  • 相关阅读:
    python3之datetime模块
    python3之time模块
    前端面试题01
    前端面试题02
    angularjs
    nodejs
    android 报错记录
    android知识点回顾二
    android知识点回顾
    Broadcast广播代码例子
  • 原文地址:https://www.cnblogs.com/chenlong-50954265/p/4969453.html
Copyright © 2011-2022 走看看