select identity(int,1,1) as id , b1 into #tmp from
(select top 3 b1 from table2 order by time desc)
a
order by b1select * from #tmpdrop table #tmp
(select top 3 b1 from table2 order by time desc)
a
order by b1select * from #tmpdrop table #tmp
调试欢乐多
id b1 time
1 data1 2004.3.13
1 data2 2004.3.12
1 data3 2004.3.11
2 data4 2004.3.13
3 data5 2004.3.14select top 5 a.id,a.b1 from table1 a,(select id,max(time)as time from table2 group by id) b where a.id=b.id and a.time=b.time order by a.id
两条sql语句也行啊。
from 表2 a join
( select id,max([time]) as maxtime
from 表2
group by id
) b
on a.id=b.id and a.time=b.maxtime