日期:2014-05-16 浏览次数:20550 次
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'
go
select *
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())