INSERT INTO xsyb  
         ( months,   
           spbm,   
           xlbm,   
           ghsbm,   
           xssl,   
           xsje,   
           xsml,   
           zxdbm )  
  SELECT dpxstjb.spbm,   
         spb.xlbm,   
         spb.ghsbm,
(select sum(A.xssl) from dpxstjb A where dpxstjb.spbm = A.spbm and dpxstjb.rq = A.rq),
(select sum(B.xszj) from dpxstjb B where dpxstjb.spbm = B.spbm and dpxstjb.rq = B.rq),
(select sum(C.xssl - C.jqjj * C.xssl) from dpxstjb C where dpxstjb.spbm = C.spbm and dpxstjb.rq = C.rq)
   FROM dpxstjb,   
         spb  
   WHERE dpxstjb.spbm = spb.spbm and  
         dpxstjb.rq >= :ybstart AND  
         dpxstjb.rq <= :ybend
 ;

解决方案 »

  1.   

    注意:select sum(A.xssl) from dpxstjb A where dpxstjb.spbm = A.spbm and dpxstjb.rq = A.rq
    where 后跟表dpxstjb的关键字即可
      

  2.   

    INSERT INTO xsyb  
             ( months,   
               spbm,   
               xlbm,   
               ghsbm,   
               xssl,   
               xsje,   
               xsml,   
               zxdbm )  
      SELECT 常数 as months,
             dpxstjb.spbm,   
             spb.xlbm,   
             spb.ghsbm,   
             sum(dpxstjb.xssl),   
             sum(dpxstjb.xszj),   
             sum(dpxstjb.xszj - dpxstjb.jqjj*dpxstjb.xssl)  
       FROM dpxstjb,   
             spb  
       WHERE ( dpxstjb.spbm = spb.spbm ) and  
             ( ( dpxstjb.rq >= :ybstart ) AND  
             ( dpxstjb.rq <= :ybend ) )    
      

  3.   

    好像少了一个字段,不知道要怎么计算,总的来说可以:insert a(x,y,z)
    select 常数 as x,y,z from b
    where ....这里 y,z 从 b表取数,X设置未常数
      

  4.   

    INSERT INTO user_code(user_name,purview_order,purview_type,purview_name,
    user_purview,user_password)
    SELECT :ls_user,purview_order,purview_type,purview_name,0,:ls_pass FROM purview_code;