if object_id('[table1]') is not null drop table [table1] go create table [table1]([a] int,[b] int,[c] int) insert [table1] select 0,100,10 union all select 100,200,20if object_id('[table2]') is not null drop table [table2] go create table [table2]([d] int,[e] int) insert [table2] select 90,12 union all select 120,13select * from table2 t where exists(select 1 from table1 where t.d between a and b and t.e<=c) /* d e ----------- ----------- 120 13(1 行受影响) */
楼主最后一个条件 且 table1.e <= table2.c 写错了,应该是: table2.e <= table1.c 吧?create table table1(a int,b int,c int) insert table1 values(0,100,10) insert table1 values(100,200,20)create table table2(d int,e int) insert table2 values(90,12) insert table2 values(120,13)select table2.d,table2.e from table1,table2 where table2.d >= table1.a and table2.d <=table1.b and table2.e <= table1.c /* d e ----------- ----------- 120 13 */
declare @tabl1 table(a int, b int, c int)
insert @tabl1 select 0 , 100 , 10 insert @tabl1 select 100, 200, 20 declare @table2 table(d int,e int) insert @table2 select 90, 12 insert @table2 select 120 ,13 select * from @table2 a where exists(select 1 from @tabl1 where a.d >= a and a.d <=b and a.e<=c ) /* d e ----------- ----------- 120 13(所影响的行数为 1 行) */
go
create table [table1]([a] int,[b] int,[c] int)
insert [table1] select 0,100,10
union all select 100,200,20if object_id('[table2]') is not null drop table [table2]
go
create table [table2]([d] int,[e] int)
insert [table2] select 90,12
union all select 120,13select * from table2 t where exists(select 1 from table1 where t.d between a and b and t.e<=c)
/*
d e
----------- -----------
120 13(1 行受影响)
*/
table2.e <= table1.c 吧?create table table1(a int,b int,c int)
insert table1 values(0,100,10)
insert table1 values(100,200,20)create table table2(d int,e int)
insert table2 values(90,12)
insert table2 values(120,13)select table2.d,table2.e from table1,table2 where table2.d >= table1.a and table2.d <=table1.b and table2.e <= table1.c
/*
d e
----------- -----------
120 13
*/
insert @tabl1 select 0 , 100 , 10
insert @tabl1 select 100, 200, 20 declare @table2 table(d int,e int)
insert @table2 select 90, 12
insert @table2 select 120 ,13
select * from @table2 a where exists(select 1 from @tabl1 where a.d >= a and a.d <=b and a.e<=c )
/*
d e
----------- -----------
120 13(所影响的行数为 1 行)
*/