日期:2014-05-18 浏览次数:20723 次
declare @VipPlan table (ID int,fanganhao int)
insert into @VipPlan
select 1,111 union all
select 2,222
declare @VipProgress table (ID int,fanganhao int,[datetime] datetime,weight int)
insert into @VipProgress
select 1,111,'2012-2-1',50 union all
select 2,222,'2012-2-1',51 union all
select 3,111,'2012-2-4',50 union all
select 4,111,'2012-2-2',53
select b.id as bid,b.fanganhao as afanganhao,
a.id as aid,a.[datetime],a.weight from @vipplan b
left join @vipprogress a
on a.fanganhao=b.fanganhao
where [datetime]=(select max([datetime]) from @vipprogress where fanganhao=a.fanganhao)
/*
bid afanganhao aid datetime weight
----------- ----------- ----------- ----------------------- -----------
2 222 2 2012-02-01 00:00:00.000 51
1 111 3 2012-02-04 00:00:00.000 50
*/