zoukankan      html  css  js  c++  java
  • 多个结果集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

  • 相关阅读:
    1002. A+B for Polynomials
    1010. 一元多项式求导
    BZOJ3569
    BZOJ3224
    loj2291. 「THUSC 2016」补退选
    平衡树入门
    高斯消元入门
    写手vector
    矩阵乘法入门
    母函数入门
  • 原文地址:https://www.cnblogs.com/SpiritWalker/p/11321304.html
Copyright © 2011-2022 走看看