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
本文介绍了一个使用SQL语句创建临时表并进行数据插入的例子,随后通过TOP与GROUP BY子句组合来选取特定数量的最新记录进行展示。
4万+

被折叠的 条评论
为什么被折叠?



