Week 4 - What Is Olap

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

What is OLAP?

- Online analytical Processing (OLAP) is a process of data analysis for information stored in a relational database - OLAP is based on facts and all facts are numbers. The numbers in the OLAP spreadsheet are called facts. - Typical facts would be: o Sales Quantity o Sales Count o Profit o Hours of work Types of OLAP - There are three prominent architectures for OLAP systems namely: o Multidimensional Online Analytical Processing (MOLAP) o Relational Online Analytical Processing (ROLAP) o Hybrid Online Analytical Processing (HOLAP) Advantage of Using OLAP - Multidimensional - Consistently fast - Intuitive Interface - Complex calculations Using Rollup Operation - The ROLLUP operation is used when you want to get a result set showing totals and subtotals. - SYNTAX o SELECT ... o FROM ... o WHERE ... o GROUP BY ROLLUP (column1, column2, ..)

Example 1: SELECT year (order_date) AS Year, quarter (order_date) AS Quarter, COUNT (*) AS Orders FROM sales_order GROUP BY ROLLUP (Year, Quarter) ORDER BY Year, Quarter Year 1 2 3 4 5 6 7 8 9 10 Example 2: SELECT year (order_date) AS Year, quarter (order_date) AS Quarter, region, COUNT (*) AS Orders FROM sales_order WHERE region IN (South,Western) AND quarter IN (1,2) GROUP BY ROLLUP (Year, Quarter, Region) ORDER BY Year, Quarter, Region Year 1 2 3 4 5 6 (NULL) 2000 2000 2000 2000 2000 Quarter (NULL) (NULL) 1 1 1 2 Region (NULL) (NULL) (NULL) South Western (NULL) Orders 92 43 23 12 11 20 (NULL) 2000 2000 2000 2000 2000 2001 2001 2001 2001 Quarter (NULL) (NULL) 1 2 3 4 (NULL) 1 2 3 Orders 648 380 87 77 91 125 268 139 119 10

7 8 9 10 11 12 13 14 15

2000 2000 2001 2001 2001 2001 2001 2001 2001

2 2 (NULL) 1 1 1 2 2 2

South Western (NULL) (NULL) South Western (NULL) South Western

12 8 49 30 14 16 19 22 8

Using Cube Operation - The CUBE operation is produces subtotals for all possible combinations of the columns listed in the group by clause. - Like ROLLUP the CUBE operator provides subtotals of aggregate values in the result set. - SYNTAX o SELECT ... o FROM ... o WHERE ... o GROUP BY CUBE (Column1 column2, ..) Example 1: SELECT year (order_date) AS Year, quarter (order_date) AS Quarter, COUNT (*) AS Orders FROM sales_order GROUP BY CUBE (Year, Quarter) ORDER BY Year, Quarter Year 1 2 3 4 5 (NULL) (NULL) (NULL) (NULL) (NULL) Quarter (NULL) 1 2 3 4 Orders 648 226 196 101 125

6 7 8 9 10 11 12 13 14

2000 2000 2000 2000 2000 2001 2001 2001 2001

(NULL) 1 2 3 4 (NULL) 1 2 3

380 87 77 91 125 268 139 119 10

Using Grouping Set Operation - GROUPING SETS allows you to compute groups on several different sets of grouping columns in the same query. - It is useful if you would like to return only part of the multidimensional result set of a cube. - SYNTAX o SELECT ... o FROM ... o WHERE ... o GROUP BY GROUPING SETS ((column1, column2), (column2), ..) Example 1: SELECT year (order_date) AS Year, quarter (order_date) AS Quarter, COUNT (*) AS Orders FROM sales_order GROUP BY GROUPING SETS ((Year, Quarter), (Year)) ORDER BY Year, Quarter Year 1 2 3 4 5 6 2000 2000 2000 2000 2000 2001 Quarter (NULL) 1 2 3 4 (NULL) Orders 380 87 77 91 125 268

7 8 9

2001 2001 2001

1 2 3

139 119 10

OLAP Functions - OLAP functions provide the capability to perform analytic task on data. - OLAP functions: o Window aggregate functions AVG MAX MIN SUM CUM_DIST DENSE_RANK PERCENT_RANK RANK ROW_NUMBER

o Window ranking function

o Row numbering functions

You might also like