当前位置: 移动技术网 > IT编程>数据库>MSSQL > 多个结果集union后保持各自原有排序

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

2019年08月08日  | 移动技术网IT编程  | 我要评论

afu,台湾教育部,猪头三网

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

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网