给定了一列数字,需要判定该列中连续的数据字有多少条记录:
field1,field2123,1 123-1124,2 124-2125,3 125-3127,4128,5create table tbl(field1 int,field2 int)insert into tbl(field1,field2) values(123,1);insert into tbl(field1,field2) values(124,2);insert into tbl(field1,field2) values(125,3);insert into tbl(field1,field2) values(127,4);insert into tbl(field1,field2) values(128,5);insert into tbl(field1,field2) values(159,6);insert into tbl(field1,field2) values(160,7);insert into tbl(field1,field2) values(167,8);select * from tblselect t10.field1,t10.field2,t11.delta,t11.coufrom (select field1,field2,field1-field2 as delta from tbl) t10inner join(select delta,count(0) as cou from (select field1,field2,field1-field2 as delta from tbl) tbl_t group by delta) t11 on t10.delta=t11.delta