blog.Toby

  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  130 随笔 :: 2 文章 :: 150 评论 :: 0 Trackbacks

DECLARE @temp table(CODE int,TOTALAMOUNT int)
declare @code int
declare row_cur scroll cursor for
select distinct code from dbo.His_Day_1 order by code
open row_cur
fetch first from row_cur into @code
while @@fetch_status=0
 begin
  insert into @temp(code,totalamount)
  select code,avg(totalamount) from 
  (select top 5 code,totalamount from dbo.His_Day_1 where code=@code order by time desc) a group by code
  fetch next from row_cur into @code
 end
close row_cur
deallocate row_cur

select * from @temp order by code

posted on 2006-12-02 11:14 渠上月 阅读(253) 评论(0)  编辑  收藏 所属分类: sql (sqlServer)

只有注册用户登录后才能发表评论。


网站导航: