日期:2014-05-17 浏览次数:20580 次
create table A (UserID nvarchar(10),SupID nvarchar(10),RegisterDate datetime)
insert into A values ('UserB','UserA','2013-05-05')
insert into A values ('UserC','UserB','2013-07-05')
insert into A values ('UserD','UserC','2013-08-05')
insert into A values ('UserE','UserD','2013-06-05')
create table B (UserID nvarchar(10))
insert into B values ('UserA')
insert into B values ('UserB')
insert into B values ('UserC')
insert into B values ('UserD')
select b.UserID
from A a
INNER JOIN B b
ON a.SupID=b.UserID
where a.SupID not in(
select SupID
from A
where RegisterDate>DATEADD(mm,-3,GETDATE()))
/*
UserA
UserD
*/
select b.*
from TableB b
where not exists(select 1 from TableA a
where b.SupID=a.UserID
and A.RegisterDate between DATEADD(month,-3,getdate()) and GETDATE())