zoukankan      html  css  js  c++  java
  • 对 union 结果进行排序

    # 第一种排序      
      select msgId ,body ,[from] ,[to] ,timetag ,attach ,convType ,type as msgType
            from MessageRecord 
            where [from] = 'aaa' and [to] = 'bbb'  and timetag < '1625220012990'
            UNION
            select msgId ,body ,[from] ,[to] ,timetag ,attach ,convType ,type as msgType
            from MessageRecord
            where [to] = 'bbb' and [from] = 'aaa' and timetag < '1625220012990'
            order by timetag DESC;
                    
    # 第二种排序
        select  row_number() over (order by timetag DESC) row_num, * FROM
        (
                    (select msgId ,body ,[from] ,[to] ,timetag ,attach ,convType ,type as msgType
                        from MessageRecord 
                        where [from] = 'aaa' and [to] = 'bbb'  and timetag < '1625220012990'
                    )
                        UNION
                    (select msgId ,body ,[from] ,[to] ,timetag ,attach ,convType ,type as msgType
                        from MessageRecord
                        where [to] = 'bbb' and [from] = 'aaa' and timetag < '1625220012990'
                    )
        )temp;
     
  • 相关阅读:
    CSS 选择器
    HTML lable和fieldset
    html image和表格
    HTML a标签
    html 提交后台的标签
    HTML INPUT系列使用
    HTML内标签、换行
    HTML 头部详解
    单例模式
    const 指针的三种使用方式
  • 原文地址:https://www.cnblogs.com/ming-blogs/p/14964379.html
Copyright © 2011-2022 走看看