没有表结构和详细的条件1和条件2,不能说得很清楚.大致如下:A表的条件1的查询结果用一个子查询返回,在此基础上进行条件2的累计,累计的结果虽然是一条记录,但是将此记录做为一个临时表temp.
insert into table as select * from temp .
将上面两次返回的sql语句取代temp基本就成这样:insert into table as select t2.* from ( select t1.* from (select * from A where 条件1) t1 where 条件1) t2;

解决方案 »

  1.   

    t1.* 可以展开成各个字段名,对要累计得字段sum(t1.col)即可.
      

  2.   

    select colname from a where colname='A'
    union all
    select sum(colname2) from a where colname='B' group by ...;
      

  3.   

    bzszp(SongZip) ,版主,楼主的意思好像最终的结果是插入而不是查询.
      

  4.   

    不知道楼主什么意思。
    插入加上insert into ... 就行了。
      

  5.   

    抱歉,意思没有表达清楚,表A有三个个字段:类别type,金额 money,时间 date,
    要出的报表格式是:
    类别|去年金额累计|本年金额累计|本月金额 报表的后三个字段都是从money字段来的,只是时间范围不同,只取,不插入
      

  6.   

    select b1.col_type,b1.s_yold,b2.s_y,b3.s_m from 
    (select col_type,sum(money) s_yold from a 
    where to_char(col_date,'yyyy')=to_char(sysdate,'yyyy')-1 group by col_type) b1
    (select col_type,sum(money) s_y from a 
    where to_char(col_date,'yyyy')=to_char(sysdate,'yyyy') group by col_type ) b2
    (select col_type,sum(money) s_m from a 
    where to_char(col_date,'yyyymm')=to_char(sysdate,'yyyymm') group by col_type) b3    
    where b1.col_type=b2.col_type and b1.col_type=t3.col_type;