没有表结构和详细的条件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;
解决方案 »
- 误删了表,但是在recyclebin 里找不到
- asp.net mvc 加 ORCLE开发,多个客户端只有一个ORACLE SESSION
- oracle中的clob类型转成server2000的什么类型合适
- 高手们进来帮帮忙
- 请教一存储过程问题(急)
- Sql执行慢
- 函数如何返回表值?
- 求一SQL语句,急ing~~~~~~~
- 大家谁有ORACLE Developer/2000 的开发指南或者教学之类的电子书?200分
- The SourceSet 'instrumentTest' is not recognized by the Android Gradle Plugin. P
- 求救!我的OracleOraHome92ManagementServer启动不了
- 自增自增,大家再不帮我,估计我就要去跳珠海了!!!!!!!!!!!!!
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;