多个结果集union后保持各自原有排序
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
上一篇: JavaScript 高阶函数