PCB MS SQL 排序应用---SQL相邻数据区间值求解
Posted pcbren
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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)
以上是关于PCB MS SQL 排序应用---SQL相邻数据区间值求解的主要内容,如果未能解决你的问题,请参考以下文章
PCB MS SQL 标量函数(CLR) 实现Socket发送消息