Multi-level data aggregation

Source: Internet
Author: User

Solution: 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 ('20140901', 100, 1 ); insert into t_20120512_a values ('20140901', 101001, 2); insert into values ('20140901', 101002, 3); commit; www.2cto.com insert into t_20120512_ B values ', 'China', null); insert into t_20120512_ B values ('123', 'Physical ', null); insert into t_20120512_ B values ('123', 'electric', null ); insert into t_20120512_ B values ('20140901', 'mechanic ', null); commit; select. id, B. name,. 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. id = B. id;
Author: Blue Paper

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.