没有表结构和详细的条件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;
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;
union all
select sum(colname2) from a where colname='B' group by ...;
插入加上insert into ... 就行了。
要出的报表格式是:
类别|去年金额累计|本年金额累计|本月金额 报表的后三个字段都是从money字段来的,只是时间范围不同,只取,不插入
(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;