日期:2014-05-18 浏览次数:20698 次
create table tb(A int,B int,C int) insert into tb select 123,222,23 insert into tb select 223,221,23 insert into tb select 223,256,26 insert into tb select 123,22,27 insert into tb select 123,126,29 insert into tb select 223,225,558 insert into tb select 223,256,25 insert into tb select 123,223,30 go select a.* from tb a inner join( select * from tb a where exists(select 1 from tb where a=a.a and c<>a.c and c-a.c between 1 and 3) and exists(select 1 from tb where a=a.a and c<>a.c and a.c-c between 1 and 3) )b on a.a=b.a and abs(a.c-b.c)<=3 /* A B C ----------- ----------- ----------- 123 22 27 123 126 29 123 223 30 223 221 23 223 256 26 223 256 25 (6 行受影响) */ go drop table tb
------解决方案--------------------
没赶上
------解决方案--------------------
create table tb(A int,B int,C int) insert into tb select 123,222,23 insert into tb select 223,221,23 insert into tb select 223,256,26 insert into tb select 123,22,27 insert into tb select 123,126,29 insert into tb select 223,225,558 insert into tb select 223,256,25 insert into tb select 123,223,30 go select a.* from tb a inner join( select a,c from tb t where exists(select 1 from tb where a=t.a and c<>t.c and c-t.c between 0 and 3 group by a having count(*)=2) )b on a.a=b.a and a.c-b.c between 0 and 3 /* A B C ----------- ----------- ----------- 123 22 27 123 126 29 123 223 30 223 221 23 223 256 26 223 256 25 (6 行受影响) */ go drop table tb