欢迎来到Doc100.Net免费学习资源知识分享平台!
您的位置:首页 > 程序异常 >

一个关于cursor的题,

更新时间: 2014-01-05 02:21:28 责任编辑: Author_N1

 

一个关于cursor的题,求助~~
In   the   task,you   will   complete   a   cursor   that   inserts   data   into   a   table,When   complete,the   script   creats   a   cursor   that   read   every   type   from   the   titles   table,determines   the   average   price   for   titles   of   titles   of   that   type.and   then   inserts   the   information   into   the   types   table.
The   script   is   supposed   to   do   the   following:
    a.   Create   a   read-only   cursor   called   type_insert   on   titles   that              
          queries   distinct   data   in   the   type   column.
    b.   Declare   two   variables:a   char(12)   value   called   @type   and   a  
          money   variable   called   @avg_price.
    c.   Open   the   cursor   and   fetch   the   first   row   into   a   targer   list.
    d.   While   there   are   rows   remaining,calulate   the   average   price       for   the   fetched   type,insert   the   appropriate   information   into   the
          types   table,and   fetch   the   next   row.
    e.   Display   the   data   in   the   types   table.

题目就是这样的,用到pubs2里的titles表,这个题里需要新建一个types表,从titles里取一条数据,处理之后就放在types里,请会的人帮我写一下d的语句吧,我实在不会了。谢谢
    f.   Close   and   deallocata   the   cursor.

--参考方法--
给你一个相近的例子吧,可以参考一下,流程都是这样的

declare @clbm varchar(20),@clph varchar(20),@cldj decimal(12,6),@clje decimal(15,2)
declare cur_fdj cursor for
select a.clbm,a.clph,b.cldj,b.cldj*a.cksl
from u_material_ckckd a,u_material_dhjyrkjsd b
where (a.clbm=b.clbm) and (a.clph=b.scbh)
open cur_fdj
fetch into cur_fdj
@clbm,@clph,@cldj,@clje
while @@sqlstatus=0
begin
update u_material_ckckd
set
cldj=@cldj,
clje=@clje
where (clbm=@clbm) and (clph=@clph)
end
fetch into cur_fdj
@clbm,@clph,@cldj,@clje
close cur_fdj
;
上一篇:上一篇
下一篇:下一篇

 

随机推荐程序问答结果

 

 

如对文章有任何疑问请提交到问题反馈,或者您对内容不满意,请您反馈给我们DOC100.NET论坛发贴求解。
DOC100.NET资源网,机器学习分类整理更新日期::2014-01-05 02:21:28
如需转载,请注明文章出处和来源网址:http://www.doc100.net/bugs/t/8839/
本文WWW.DOC100.NET DOC100.NET版权所有。