数据库

 首页 > 数据库 > Oracle > 关于多层级数据汇总的问题

关于多层级数据汇总的问题

分享到:
【字体:
导读:
         摘要:解决方案:createtablet_20120512_a(idvarchar2(6)primarykey,costnumber(3),www.2cto.comp2number(3),p3number(3))/createtablet_20120512_b(idvarchar2(6)primarykey,namev......

关于多层级数据汇总的问题
 
 
解决方案:
 
create table t_20120512_a (
id varchar2(6) primary key,
cost number(3),  www.2cto.com  
p2 number(3),
p3 number(3)
)
/
create table t_20120512_b
(
id varchar2(6) primary key,
name varchar2(50),
b varchar2(100)
)
/
insert into t_20120512_a values ('100',1,1,1);
insert into t_20120512_a values ('101001',2,2,2);
insert into t_20120512_a values ('101002',3,3,3);
commit;  www.2cto.com  
insert into t_20120512_b values ('100','语文',null);
insert into t_20120512_b values ('101','物理',null);
insert into t_20120512_b values ('101001','电学',null);
insert into t_20120512_b values ('101002','力学',null);
commit;
 
select a.id, b.name ,a.total from
(
select distinct case when GROUPING(substr(id,1,3))=0 then substr(id,1,3) else id end id,sum(cost) total from t_20120512_a group by grouping SETS (id,substr(id,1,3))
) a,
t_20120512_b b 
where a.id=b.id;

 
 
作者 蓝红石
关于多层级数据汇总的问题
分享到:
Oracle共享池简析
Oracle共享池简析 Oracle共享池 Oracle共享池(Share Pool)属于SGA,由库高速缓存(library cache)和数据字 典高速缓存(data dictionary cache)组成。 库高速缓存  www.2cto.com   Oracle引入库高速缓存的目的是共享SQL和PL/SQL代码。   服务器进程执行SQL和PL/SQL时,首先会进入库高速缓存查找是否有相同的SQL, ...
ORA-00845:MEMORY_TARGET导致Ubuntu升级1...
ORA-00845:MEMORY_TARGET导致Ubuntu升级12.04无法启动的问题 ORA-00845:MEMORY_TARGET导致Ubuntu升级12.04无法启动的问题   安装了oracle11g的ubuntu升级到12.04启动是报错误ORA-00845: MEMORY_TARGET not supported on this system。  原因12.04中将/dev/shm目录改成了/run/shm,虽然已经有符号链接但是仍然报错。    ...
  •         php迷,一个php技术的分享社区,专属您自己的技术摘抄本、收藏夹。
  • 在这里……