Team Fly 

Page 345

In the results, we can see that counts and sums of amount_sold are returned at the following levels:

Image By GENDER, CHANNEL_CLASS, and MONTH

Image Subtotals by CHANNEL_CLASS within GENDER

Image Subtotals by GENDER

Image Grand total

cube

The cube extension takes rollup a step further by generating subtotals for each combination of the group by attributes, totals by attribute, and the grand total. The following is an example of the cube extension, using the same query we used for rollup:

select c.cust_gender gender,
       b.channel_class channel_class,
       to_char(a.time_id, 'yyyy-mm') month,
       count(*) unit_count,
       sum(a.amount_sold) amount_sold
from sales a, channels b, customers c
where a.channel_id = b.channel_id
and   a.cust_id = c.cust_id
and   to_char(a.time_id, 'yyyy-mm') between '2001-01' and '2001-02'
group by cube(c.cust_gender,
                b.channel_class,
                to_char(a.time_id, 'yyyy-mm'));

GENDER CHANNEL_CLASS        MONTH   UNIT_COUNT AMOUNT_SOLD
------ -------------------- ------- ---------- -----------
                                         39924  4216833.67
                            2001-01      20739  2113709.13
                            2001-02      19185  2103124.54
       Direct                            20427  2113199.92
       Direct               2001-01      11039  1106147.18
       Direct               2001-02       9388  1007052.74
       Others                            12603  1278645.06
       Others               2001-01       6796   657218.93
       Others               2001-02       5807   621426.13
       Indirect                           6894   824988.69
       Indirect             2001-01       2904   350343.02
       Indirect             2001-02       3990   474645.67
F                                        14274  1552931.54
F                           2001-01       7540   768012.01
F                           2001-02       6734   784919.53
F      Direct                             7209   752861.03
F      Direct               2001-01       4001    387000.9
Team Fly 
0364