多个结果集union后保持各自原有排序

2022-10-17,,

select *
from (
select top (@count1) a.* from article as a with (nolock)
left join article_type as at with (nolock)
on a.articletype=at.articletypeid
where a.isdelete=0 and a.status=0
and at.articletypeid=@articletype1---条件变换
and a.issuetime<getdate()
order by a.issuetime desc,a.articletype asc
) t
union all
select *
from (
select top (@count2) a.* from article as a with (nolock)
left join article_type as at with (nolock)
on a.articletype=at.articletypeid
where a.isdelete=0 and a.status=0
and at.articletypeid=@articletype2---条件变换
and a.issuetime<getdate()
order by a.issuetime desc,a.articletype asc
) t
union all
select *
from (
select top (@count3) a.* from article as a with (nolock)
left join article_type as at with (nolock)
on a.articletype=at.articletypeid
where a.isdelete=0 and a.status=0
and at.articletypeid=@articletype3 ---条件变换
and a.issuetime<getdate()
order by a.issuetime desc,a.articletype asc
) t

《多个结果集union后保持各自原有排序.doc》

下载本文的Word格式文档,以方便收藏与打印。