blog.Toby

            BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
            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)
          主站蜘蛛池模板: 玉门市| 谷城县| 甘肃省| 剑川县| 峡江县| 正蓝旗| 三门县| 平潭县| 河西区| 柳河县| 济宁市| 宁安市| 惠来县| 洱源县| 垫江县| 观塘区| 新巴尔虎左旗| 乐都县| 饶河县| 温泉县| 亳州市| 灯塔市| 浏阳市| 治县。| 时尚| 会泽县| 常熟市| 绥德县| 逊克县| 拉萨市| 临汾市| 灵山县| 玉环县| 兴山县| 麻阳| 镶黄旗| 吉林市| 松溪县| 临颍县| 元谋县| 哈巴河县|