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

  • 相关阅读:
    第11章 接口与内部类
    第10章 多态
    API接口设计之token、timestamp、sign具体实现
    JDK 监控和故障处理工具
    分布式id生成方案
    SQL优化
    自定义对象存入Redis
    OAuth(开放授权)
    Hystrix使用
    Session机制详解
  • 原文地址:https://www.cnblogs.com/SpiritWalker/p/11321304.html
Copyright © 2011-2022 走看看