Let's look at an example using the OLAPTRAIN schema. Suppose you want the total of the states in the northeastern United States. In OLAPTRAIN, that would include Massachusetts, Rhode Island, New York and Pennsylvania..
If you did this with SQL, it might look something like this.
g.country_long_description AS country,
p.all_products_long_descri AS all_products,
c.all_channels_long_descri AS all_channels,
SUM(f.sales)
FROM time_calendar_view t,
product_standard_view p,
geography_regional_view g,
channel_sales_channel_view c,
sales_cube_view f
WHERE t.dim_key = f.time
AND p.dim_key = f.product
AND g.dim_key = f.geography
AND c.dim_key = f.channel
AND t.level_name = 'CALENDAR_YEAR'
AND p.level_name = 'ALL_PRODUCTS'
AND c.level_name = 'ALL_CHANNELS'
AND g.level_name = 'STATE_PROVINCE'
AND g.state_province_long_desc IN ('Massachusetts','Rhode Island','New York', 'Pennsylvania')
AND t.calendar_year_long_descr = 'CY2009'
AND g.country_long_description = 'United States'
GROUP BY t.calendar_year_long_descr,
g.country_long_description,
p.all_products_long_descri,
c.all_channels_long_descri;
And the query would return as
A different way to approach this is to create a custom member that is the aggregate of other members. In this case, the custom member is added to the dimension and can be used just like any other dimension member. The only real difference is that a custom member is not within a hierarchy and does not belong to a level. The advantages are that the custom member is available to all users (unless you control access, more on that later), they work with all of the cube's aggregation rules (e.g., first, last, hierarchical weighted average and so on), they work seamlessly with calculated measures and they are available in all tools (e.g., Excel PivotTables).
Custom aggregates are created using the dbms_cube.import program. Note that the dimension keys are numeric in OLAPTRAIN. (Sorry for posting this sample as an image ... blogger wasn't happy about displaying XML. To view the full example option the image in a new tab or window).
g.long_description AS geog,
p.long_description AS product,
c.long_description AS channel,
f.sales
FROM time_calendar_view t,
product_standard_view p,
geography_regional_view g,
channel_sales_channel_view c,
sales_cube_view f
WHERE t.dim_key = f.time
AND p.dim_key = f.product
AND g.dim_key = f.geography
AND c.dim_key = f.channel
AND t.level_name = 'CALENDAR_YEAR'
AND p.level_name = 'ALL_PRODUCTS'
AND c.level_name = 'ALL_CHANNELS'
AND g.long_description = 'Northeast US'
AND t.calendar_year_long_descr = 'CY2009';
