• PCB MS SQL 排序应用---SQL相邻数据区间值求解


    其中一篇 博文中有写《PCB MS SQL 排序应用---相邻数据且相同合并处理》此篇有也应相用也同的技巧,实现相邻数据区间值求解

    示例:

    原数据:处理前

    求出区间值:处理后

     SQL 代码实现

    DECLARE @table table(RowNo INT,FlowTechName VARCHAR(20))
    
    INSERT INTO @table(RowNo,FlowTechName) VALUES(1,'沉铜')
    INSERT INTO @table(RowNo,FlowTechName) VALUES(4,'钻孔')
    INSERT INTO @table(RowNo,FlowTechName) VALUES(5,'钻孔')
    INSERT INTO @table(RowNo,FlowTechName) VALUES(6,'钻孔')
    INSERT INTO @table(RowNo,FlowTechName) VALUES(7,'沉铜')
    INSERT INTO @table(RowNo,FlowTechName) VALUES(10,'沉铜')
    INSERT INTO @table(RowNo,FlowTechName) VALUES(11,'沉铜')
    INSERT INTO @table(RowNo,FlowTechName) VALUES(15,'钻孔')
    INSERT INTO @table(RowNo,FlowTechName) VALUES(18,'沉铜')
    INSERT INTO @table(RowNo,FlowTechName) VALUES(20,'钻孔')
    INSERT INTO @table(RowNo,FlowTechName) VALUES(21,'钻孔')
    INSERT INTO @table(RowNo,FlowTechName) VALUES(22,'钻孔')
     
    SELECT * FROM @table
    
    SELECT min(RowNo) minRank,MAX(RowNo) maxRank,FlowTechName
    FROM 
      (SELECT FlowTechName,RowNo,row_number()over(partition by FlowTechName order by RowNo) -RowNo DiffVal 
      FROM @table) t
    GROUP BY FlowTechName,DiffVal
    ORDER BY MAX(RowNo)
  • 相关阅读:
    Educational Codeforces Round 81 (Rated for Div. 2) A-E
    SEERC 2018 I
    manjaro linux java环境配置
    Pangu and Stones HihoCoder
    Linux下 vim 的配置
    C++内存管理技术
    Interview_C++_day27
    Interview_C++_day26
    Interview_C++_day25
    Interview_数据库_day24
  • 原文地址:https://www.cnblogs.com/pcbren/p/9270907.html
Copyright © 2020-2023  润新知