34,590
社区成员
发帖
与我相关
我的任务
分享
create table temp_1
([name] varchar(20) not null,
telno varchar(20) not null,
begin_time datetime null,
end_time datetime null,
)
insert into temp_1([name],telno,begin_time,end_time)
select 'admin','8246','2008-06-13 00:55:53.000','2008-06-13 23:55:53.000'
union
select 'admin2','8246','2008-06-14 00:55:53.000','2008-06-14 23:55:53.000'
union
select 'admin3','8246','2008-06-15 00:55:53.000','2008-06-15 23:55:53.000'
create table temp_2
(
id int identity(1,1) not null,
telno varchar(20),
u_time datetime null,
)
insert into temp_2(telno,u_time)
select '8246','2008-06-13 12:55:53.000'
union
select '8246','2008-06-13 14:55:53.000'
union
select '8246','2008-06-14 12:55:53.000'
union
select '8246','2008-06-15 12:55:53.000'
select a.name,a.telno,b.u_time from temp_1 a
inner join temp_2 b on a.telno=b.telno where b.u_time between a.begin_time and a.end_time
/*
name telno u_time
-------------------- -------------------- ------------------------------------------------------
admin 8246 2008-06-13 12:55:53.000
admin 8246 2008-06-13 14:55:53.000
admin2 8246 2008-06-14 12:55:53.000
admin3 8246 2008-06-15 12:55:53.000
(所影响的行数为 4 行)
*/