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)
          主站蜘蛛池模板: 塘沽区| 北票市| 旅游| 连平县| 莱州市| 即墨市| 抚州市| 云和县| 桐庐县| 资阳市| 大名县| 军事| 留坝县| 茂名市| 炉霍县| 当阳市| 泰兴市| 永和县| 西安市| 尉氏县| 潞城市| 巫山县| 赞皇县| 永德县| 庆元县| 日喀则市| 奉新县| 班玛县| 祁东县| 博客| 抚远县| 襄城县| 赤水市| 香河县| 明水县| 大石桥市| 临邑县| 枣阳市| 阳东县| 平江县| 遂溪县|