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 渠上月 閱讀(260) 評論(0)  編輯  收藏 所屬分類: sql (sqlServer)
          主站蜘蛛池模板: 攀枝花市| 苗栗市| 汶上县| 邳州市| 梅河口市| 驻马店市| 黎平县| 始兴县| 南召县| 上饶县| 镇赉县| 微博| 安康市| 夹江县| 库伦旗| 思南县| 延寿县| 晋宁县| 沂源县| 贵南县| 吴江市| 小金县| 迁安市| 炉霍县| 台南市| 恩施市| 保山市| 尤溪县| 淳化县| 凤翔县| 澜沧| 伊宁县| 竹北市| 葵青区| 凤城市| 汪清县| 开化县| 房产| 建阳市| 秦皇岛市| 白沙|