首页 > 编程语言 > 详细

对 union 结果进行排序

时间:2021-07-02 23:04:22      阅读:19      评论:0      收藏:0      [点我收藏+]
# 第一种排序      
  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;

 

 

对 union 结果进行排序

原文:https://www.cnblogs.com/ming-blogs/p/14964379.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!