这样吗: create table Account(AccountId int,modifiedOn datetime)insert into Account select 1 ,'2013-03-04' union all select 2 ,'2014-02-02' union all select 3 ,'2013-11-24'create table Activity(accountId int,createdOn datetime)insert into Activity select 1 ,'2014-02-01' union all select 2 ,'2013-11-11' union all select 3 ,'2013-12-01' goselect * from ( select accountId,MAX(modifiedOn) as date from ( select * from ACCOUNT union all select * from Activity )t group by accountId )t where date <= datediff(day,45,getdate())
create table Account(AccountId int,modifiedOn datetime)insert into Account
select 1 ,'2013-03-04' union all
select 2 ,'2014-02-02' union all
select 3 ,'2013-11-24'create table Activity(accountId int,createdOn datetime)insert into Activity
select 1 ,'2014-02-01' union all
select 2 ,'2013-11-11' union all
select 3 ,'2013-12-01'
goselect *
from
(
select accountId,MAX(modifiedOn) as date
from
(
select * from ACCOUNT
union all
select * from Activity
)t
group by accountId
)t
where date <= datediff(day,45,getdate())