# 第一种排序      
  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;

 

 

相关文章:

  • 2021-11-18
  • 2022-12-23
  • 2021-09-13
  • 2021-04-15
  • 2022-12-23
  • 2022-01-27
  • 2022-12-23
猜你喜欢
  • 2021-10-26
  • 2021-12-24
  • 2022-12-23
  • 2021-12-31
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案