日期:2014-05-18 浏览次数:20690 次
create table a (id int,name nvarchar(32),out_date date) go insert a select 1,'电视1','2012-02-01' union all select 2,'电视1','2012-03-20' union all select 3,'电视1','2012-02-06' union all select 4,'电视2','2012-02-23' create table b (id int,name nvarchar(32),price money,ord_date date) go insert b select 1,'电视1',3500,'2011-04-12' union all select 2,'电视1',3000 ,'2011-12-21' union all select 3,'电视1',2800 ,'2012-03-04' union all select 4,'电视1',4000,'2012-1-16' select a.name,prices=(select top 1 price from b where out_date>ord_date order by ord_date desc),out_date from a /* name prices out_date 电视1 4000.00 2012-02-01 电视1 2800.00 2012-03-20 电视1 4000.00 2012-02-06 电视2 4000.00 2012-02-23 */