22,199
社区成员
发帖
与我相关
我的任务
分享
select * from price a where Date in(select max(Date) from price where name=a.name group by name)
declare @price table (id int identity(1,1),name varchar(10),date datetime,bidprice float)
insert into @price
select 'aaa','2007-10-06',55
union all
select 'bbb','2007-02-06',50
union all
select 'aaa','2007-02-05',60
union all
select 'ccc','2007-02-05',35
union all
select 'ddd','2007-02-04',75
union all
select 'ccc','2007-02-04',40
union all
select 'ddd','2007-02-05',49
select a.* from @price a,
(select name,max(date) date from @price
group by name) b
where a.name=b.name
and datediff(day,a.date,b.date)=0