取表中 某累记录的最大5行

来源:互联网 发布:招聘网络推广专员 编辑:程序博客网 时间:2024/06/11 22:35

 

declare @tb table (dt datetime,stockid char(6),fvol numeric(20,5))
insert into @tb select 
'2008-3-11','000800',289928.4375
insert into @tb select 
'2008-2-22','000800',503016.1875 
insert into @tb select 
'2008-2-25','000800',-10095.21582 
insert into @tb select 
'2008-2-26','000800',-36981.878906
insert into @tb select 
'2008-2-27','000800',644.995361
insert into @tb select 
'2008-2-28','000800',2198.187988 
insert into @tb select 
'2008-2-29','000800',5654.983398
insert into @tb select 
'2008-3-3','000800'5546.563965 

insert into @tb select 
'2008-3-2','600000',-24493.21875 
insert into @tb select 
'2008-2-22','600000',550059.6875  
insert into @tb select 
'2008-2-25','600000',-18295.4375  
insert into @tb select 
'2008-2-26','600000'-81992.4375 
insert into @tb select 
'2008-2-27','600000',84372.671875 
insert into @tb select 
'2008-2-28','600000',-10039.753906  
insert into @tb select 
'2008-2-29','600000',-715.375 
insert into @tb select 
'2008-3-3','600000',26328.328125 



select 
* From 
(
select  top   
10  stockid,  (dt)  ,fvol
  from   
  @tb   
 group   by stockid ,dt ,fvol
 order   by  max(dt) desc 
)c
order by stockid ,dt
原创粉丝点击