Grouping Rows with GROUP BY

Setup

Run the code on this page in SQL*Plus to create the sample tables, data, etc. used by the examples in this section.

Be sure to read Using SQL Snippets ™ before executing any of these setup steps.

create table t
( grp_a varchar2(10)
, grp_b varchar2(10)
, grp_c varchar2(10)
, grp_d varchar2(10)
, val   number
) ;

insert into t values ( 'a1' , 'b1' , 'c1', 'd1', '10' ) ;
insert into t values ( 'a1' , 'b1' , 'c1', 'd1', '20' ) ;
insert into t values ( 'a1' , 'b2' , 'c1', 'd1', '30' ) ;
insert into t values ( 'a1' , 'b2' , 'c1', 'd1', '40' ) ;
insert into t values ( 'a1' , 'b2' , 'c2', 'd1', '50' ) ;
insert into t values ( 'a2' , 'b3' , 'c2', 'd2', '12' ) ;
insert into t values ( 'a2' , 'b3' , 'c2', 'd2', '22' ) ;
insert into t values ( 'a2' , 'b3' , 'c2', 'd2', '32' ) ;

commit ;

create table t2
( grp_a varchar2(10)
, grp_b varchar2(10)
, val   number
) ;

insert into t2 values ( 'A1' , 'X1' , '10' ) ;
insert into t2 values ( 'A1' , 'X2' , '40' ) ;
insert into t2 values ( 'A1' , null , '20' ) ;
insert into t2 values ( 'A1' , null , '30' ) ;
insert into t2 values ( 'A1' , null , '50' ) ;
insert into t2 values ( 'A2' , null , '60' ) ;

commit ;
 



Linking to SQL Snippets ™

To link to this page in Oracle Technology Network Forums or OraFAQ Forums cut and paste this code.

  • [url=http://www.sqlsnippets.com/en/topic-13102.html]SQL Snippets: Grouping Rows with GROUP BY - Setup[/url]

To link to this page in HTML documents or Blogger comments cut and paste this code.

  • <a href="http://www.sqlsnippets.com/en/topic-13102.html">SQL Snippets: Grouping Rows with GROUP BY - Setup</a>

To link to this page in other web sites use the following values.

  • Link Text : SQL Snippets: Grouping Rows with GROUP BY - Setup
  • URL (href): http://www.sqlsnippets.com/en/topic-13102.html