你这group by 个游标的值 有什么用呢

解决方案 »

  1.   

    还有你这存储过程有什么用 、、、
    select count(*) exist_num,round(sum(24-y.scsj),2) exist_time,round(sum(y.lyrcyl),4 exist_oil from (select b.mc ,a.* from dba01 a,v_dab913_fpf_station b where  substr(a.jhdm,0,6)=b. station ) y where y.gjdm is not null and to_char(y.rq,'yyyymm')=P_rq and y.mc=P_Filed  group by y.gjdm
    这个能单独查出来么?
      

  2.   

    这个还没写完,我要将查出来的存到一张表里,你说我的sum单独写出来?
      

  3.   

    那你定义游标的时候就group by 然后循环去游标数据 insert到表里不行么
      

  4.   

    你上面写了一个游标,下面就用这个游标做一个group by, 想不通
    你的目的是把select count(*) into exist_num,round(sum(24-y.scsj),2) into exist_time,round(sum(y.lyrcyl),4) into exist_oil          from (select b.mc ,a.* from dba01 a,v_dab913_fpf_station b where  substr(a.jhdm,0,6)=b. station ) y
             where y.gjdm is not null and to_char(y.rq,'yyyymm')=P_rq and y.mc=P_Filed这个SQL的结果插到一个表里,正常的逻辑是你在游标里面得到你要的这个结果,然后再循环插到目标表里。楼上已经说了。目测你的SQL,这个结果是聚合函数的结果,只有一个结果,你用游标,只能循环一次,游标显得多余。还是那句话, 你在游标里面该聚合的聚合,该分组的分组,得到你要的结果后,再insert 到你的target表里。
      

  5.   

    或者我觉得 你就一个insert into table (select ...)好了。