APEX DW Lab4
APEX DW Lab4
APEX DW Lab4
Warehousing
CSIS 4320 Data Warehousing
Lab 4
Role of metadata
Querying Oracle metadata
SQL analytical processing
Advanced calculations
Role of Metadata
Technical Metadata
Metadata is meant for the IT professionals perform the
development and administration of the data warehouse
Technical metadata helps to understand DW model and
perform query
Answer questions such as
Oracle Metadata
Oracle metadata is the description about the data itself in the
database
Metadata repository
Metadata is scattered across the system
Oracle Metadata
Oracle APEX Object Browser provides convenient graphical
user interface (GUI) to view some metadata
As we have experienced in Lab 1
View Name
USER_TABLES
USER_TAB_COLUMNS
USER_CONSTRAINTS
USER_CONS_COLUMNS
USER_INDEXES
USER_IND_COLUMNS
USER_TAB_COMMENTS
USER_COL_COMMENTS
Quarter 4
Quarter 1
Quarter 4
Quarter 1
Subtotals for
Categories
Quarter 1
Subtotals for
Categories
Quarter 1
Set 3
Set 1
Set 2
Set 4
Advanced Calculations
Business information processing requires advanced
calculations
Ranking
Relative contributions to a total
Ranking
To see an additional column that shows the rank of any
revenue number within the quarter
SELECT DECODE(GROUPING(t.calendar_quarter_name),
0, t.calendar_quarter_name, 1, 'TOTAL') quarter,
DECODE(GROUPING(t.calendar_quarter_name) + GROUPING(p.category_name),
0, RANK() OVER (PARTITION BY t.calendar_quarter_name ORDER BY SUM(s.sales)),
1, null) ranking,
DECODE(GROUPING(c.class_name),
0, c.class_name, 1, '--all') channel,
DECODE(GROUPING(p.category_name),
0, p.category_name, 1, 'TOTAL') category,
TO_CHAR(SUM(s.sales),'L999G999G990D00') revenue
FROM times t, products p, channels c, sales_fact s
WHERE t.day_key = s.day_key AND p.item_key = s.product AND c.channel_key = s.channel
AND s.day_key BETWEEN TO_DATE('01-JAN-2007','dd-MON-yyyy')
AND TO_DATE('31-DEC-2007','dd-MON-yyyy')
GROUP BY GROUPING SETS(c.class_name, CUBE(t.calendar_quarter_name, p.category_name))
ORDER BY t.calendar_quarter_name, c.class_name, sum(s.sales);
Ranking
Here is the result with RANK function
Relative Contribution
To calculate the contribution of every product category to the
total revenue based on a given time period
SELECT DECODE(GROUPING(t.calendar_quarter_name),
0, t.calendar_quarter_name, 1, 'TOTAL') quarter,
DECODE(GROUPING(t.calendar_quarter_name) + GROUPING(p.category_name),
0, RANK() OVER (PARTITION BY t.calendar_quarter_name ORDER BY SUM(s.sales)),
1, null) ranking,
DECODE(GROUPING(c.class_name),
0, c.class_name, 1, '--all') channel,
DECODE(GROUPING(p.category_name),
0, p.category_name, 1, 'TOTAL') category,
TO_CHAR(SUM(s.sales),'L999G999G990D00') revenue,
TO_CHAR(100 * RATIO_TO_REPORT(SUM(s.sales))
OVER (PARTITION BY (TO_CHAR(GROUPING(p.category_name) || t.calendar_quarter_name))), '990D0') percent
FROM times t, products p, channels c, sales_fact s
WHERE t.day_key = s.day_key AND p.item_key = s.product AND c.channel_key = s.channel
AND s.day_key BETWEEN TO_DATE('01-JAN-2007','dd-MON-yyyy')
AND TO_DATE('31-DEC-2007','dd-MON-yyyy')
GROUP BY GROUPING SETS(c.class_name, CUBE(t.calendar_quarter_name, p.category_name))
ORDER BY t.calendar_quarter_name, c.class_name, sum(s.sales);
Relative Contribution
Here is the result with RATIO_TO_REPORT function
Description
ROLLUP
Group the selected rows, and returns a single row of summary for
each group.
CUBE
GROUPING
GROUPING SETS
RANK
RATIO_TO_REPORT
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: