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 渠上月 閱讀(266) 評論(0)  編輯  收藏 所屬分類: sql (sqlServer)
          主站蜘蛛池模板: 来宾市| 章丘市| 肇东市| 拉孜县| 鹤壁市| 鲁甸县| 石柱| 仙桃市| 蚌埠市| 岑巩县| 永清县| 砚山县| 三江| 离岛区| 文水县| 昔阳县| 睢宁县| 怀安县| 集贤县| 河东区| 房产| 错那县| 大悟县| 伊金霍洛旗| 福泉市| 红安县| 二连浩特市| 无为县| 和硕县| 甘肃省| 太白县| 潮州市| 晋江市| 延长县| 磐安县| 兴仁县| 永靖县| 二连浩特市| 双峰县| 日土县| 宜兰市|