首页 电脑 电脑学堂 查看内容

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

2012-5-14 14:07 796 0

摘要: 解决方案:   create table t_20120512_a ( id varchar2(6) primary key, cost number(3),  www.2...
关键词: 20120512 insert values nbsp into varchar2 id 红石 null number

解决方案:   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;     作者 蓝红石
声明:文章版权归原作者所有 部分文章转自互联网 如有侵权请联系 [邮箱地址] 删除

路过

雷人

握手

鲜花

鸡蛋

最新评论

返回顶部