Sie sind auf Seite 1von 4

Assignment No.

Title of the assignment: Implementation of data cubes. Execute queries to demonstrate the extended aggregation, ranking , pivoting, rollup & windowing. Relevant theory/Literature Survey : An OLAP (Online analytical processing) cube is a data structure that allows fast analysis of data. It can also be defined as the capability of manipulating and analyzing data from multiple perspectives. The arrangement of data into cubes overcomes a limitation of relational databases. Relational databases are not well suited for near instantaneous analysis and display of large amounts of data. Instead, they are better suited for creating records from a series of transactions known as OLTP or On-Line Transaction Processing. OLAP operations The analyst can understand the meaning contained in the databases using multidimensional analysis. By aligning the data content with the analyst's mental model, the chances of confusion and erroneous interpretations are reduced. The analyst can navigate through the database and screen for a particular subset of the data, changing the data's orientations and defining analytical calculations. The user-initiated process of navigating by calling for page displays interactively, through the specification of slices via rotations and drill down/up is sometimes called "slice and dice". Common operations include slice and dice, drill down, roll up, and pivot. Slice: A slice is a subset of a multi-dimensional array corresponding to a single value for one or more members of the dimensions not in the subset. The slice operation performs a selection on one dimension of the given cube, resulting in a sub_cube. Dice: The dice operation is a slice on more than two dimensions of a data cube (or more than two consecutive slices) The dice operation defines a sub_cube by performing a selection on two or more dimensions. Drill Down/Up: Drilling down or up is a specific analytical technique whereby the user navigates among levels of data ranging from the most summarized (up) to the most detailed (down). Roll-up: A roll-up involves computing all of the data relationships for one or more

dimensions. To do this, a computational relationship or formula might be defined. Pivot: To change the dimensional orientation of a report or page display Design Analysis/ Implementation Logic : Windowing Query Example:
SELECT 2 month, SUM(amount) AS month_amount, 3 SUM(SUM(amount)) OVER (ORDER BY month ROWS UNBOUNDED PRECEDING) AS 4 cumulative_amount 5 FROM all_sales 6 WHERE month BETWEEN 6 AND 12 7 GROUP BY month 8 ORDER BY month;

use of ROWS UNBOUNDED PRECEDING to implicitly indicate the end of the window Pivoting Example: To transpose the query output to row-value instead of column-value , it is called Pivoting ( Rows to Coulmn Conversion) in SQL. There are two methods used popularly for Pivoting in Oracle SQL( From Oracle 8i) . They are 1. Using Decode ( or CASE ) 2. Using Sys_connect_by_path 1. Using Decode This method uses Decode and group by together. Example 1 : Displays the employee names in a row for each department. SQL> SELECT deptno, 2 MAX(DECODE ( rn , 1, ename )) EMP1, 3 MAX(DECODE ( rn , 2, ename )) EMP2, 4 MAX(DECODE ( rn , 3, ename )) EMP3, 5 MAX(DECODE ( rn , 4, ename )) EMP4, 6 MAX(DECODE ( rn , 5, ename )) EMP5, 7 MAX(DECODE ( rn , 6, ename )) EMP6 8 FROM 9 (SELECT empno , ename, deptno, 10 row_number() OVER ( partition by deptno order by rownum) rn 11 FROM EMP) 12 GROUP BY deptno;

DEPTNO EMP1 EMP2 EMP3 EMP4 EMP5 EMP6 ---------- ---------- ---------- ---------- ---------- ---------- ---------10 CLARK KING MILLER 20 SMITH JONES SCOTT ADAMS FORD 30 ALLEN WARD MARTIN BLAKE TURNER JAMES 1. Using Sys_connect_by_path As Sys_connect_by_path is used along with hierarchical queries, we need to make any query in that format for doing the pivot. It returns the path of a column value from root to node, with column values separated by char for each row returned by CONNECT BY condition. Example 1 : Displays the employee names separated by comma in a row for each department. SQL> SELECT deptno , 2 LTRIM(MAX( SYS_CONNECT_BY_PATH ( ename, ',')),',') EMP_STRING 3 FROM 4 (SELECT empno , ename, deptno, 5 row_number() OVER ( PARTITION BY deptno ORDER BY rownum) rn 6 FROM EMP ) 7 CONNECT BY deptno = PRIOR deptno 8 AND rn = PRIOR rn+1 9 START WITH rn =1 10 GROUP BY deptno 11 ORDER BY deptno; DEPTNO EMP_STRING ---------- -----------------------------------------------------------10 CLARK,KING,MILLER 20 SMITH,JONES,SCOTT,ADAMS,FORD 30 ALLEN,WARD,MARTIN,BLAKE,TURNER,JAMES This method is recommended if row values are unknown or not fixed. Ranking Example: RANK is an analytic function that can be used to get the rank of a row in respect to a group of rows. QL> SELECT RANK() OVER (ORDER BY S.sales ASC) AS ranking, 2 L.city, 3 S.sales 4 FROM Sales S, Times T, Locations L

5 WHERE S.timeid=T.timeid AND S.locid=L.locid; RANKING CITY SALES ---------- --------------- ---------1 Miami 1 2 Mumbai 3 3 San Angelo 5 4 Orlando 8 4 Dallas 8 6 San Angelo 10 6 Las Vegas 10 6 San Angelo 10 6 Pune 10 10 Las Vegas 12 Conclusion: Thus we have implemented data cubes, and aggregation, ranking, pivoting, rollup & windowing operations.

Das könnte Ihnen auch gefallen