select * from tb a where exists(select * from tb where id=a.id-1 and num<>a.num)--?
create table test(id int,num varchar(10)) insert into test select 1,'0' union all select 2,'0' union all select 3,'1' union all select 4,'1' union all select 5,'1' union all select 6,'1' union all select 7,'0' union all select 8,'1' union all select 9,'1' union all select 10,'0'select * from test A where exists(select * from test where id=A.id-1 and num<>A.num); ------------------------------------------------------------------------------------- 3 1 7 0 8 1 10 0
insert into test
select 1,'0'
union all select 2,'0'
union all select 3,'1'
union all select 4,'1'
union all select 5,'1'
union all select 6,'1'
union all select 7,'0'
union all select 8,'1'
union all select 9,'1'
union all select 10,'0'select * from test A where exists(select * from test where id=A.id-1 and num<>A.num);
-------------------------------------------------------------------------------------
3 1
7 0
8 1
10 0