UNION ALL 和 order by一起使用的小坑
对比下面3次查询,第一次会报错,第二次把整体查询结果按照dealTime 倒序,如果想让union all的两个查询中都先按照指定排序取前N跳然后再union all则参考第三种方式
select top 10 * FROM data_ttpai_DealStatisticsGrab WITH ( NOLOCK ) where specId=25893 order by dealTime desc union all select top 10 * FROM data_ttpai_DealStatisticsGrab WITH ( NOLOCK ) where specId=25894 order by dealTime desc ------------------------------------------------------------------------- select top 10 * FROM data_ttpai_DealStatisticsGrab WITH ( NOLOCK ) where
共有 0 条评论