多个结果集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

posted @ 2019-08-08 15:13  Focus and Learn  阅读(2327)  评论(0编辑  收藏  举报