You are on page 1of 8

Name : Pratiksha Nimgade

Roll no : 23

PRN : 1814110641

ADBMS: Assignment – 06
Study and demonstrating of OLAP operations in SQL:

OLAP (online analytical processing) is a computing method that enables users to easily and
selectively extract and query data in order to analyze it from different points of view. OLAP business
intelligence queries often aid in trends analysis, financial reporting, sales forecasting, budgeting and
other planning purposes.

For example, a user can request that data be analyzed to display a spreadsheet showing all of a
company's beach ball products sold in Florida in the month of July, compare revenue figures with
those for the same products in September and then see a comparison of other product sales in
Florida in the same time period.

How OLAP systems work


To facilitate this kind of analysis, data is collected from multiple data sources and stored in data
warehouses then cleansed and organized into data cubes. Each OLAP cube contains data categorized
by dimensions (such as customers, geographic sales region and time period) derived by dimensional
tables in the data warehouses. Dimensions are then populated by members (such as customer
names, countries and months) that are organized hierarchically. OLAP cubes are often pre-
summarized across dimensions to drastically improve query time over relational databases.

Brief history
The term OLAP firstly appeared in 1993. It was invented by ‘the father of the relational database’
Edgar F. Codd in his article Providing OLAP (On-Line Analytical Processing) to User-Analysts: An IT
Mandate. But the idea of processing multidimensional data dates back to 1962, when Ken Iverson
published his work A Programming Language, APL.  This language was used in many business
applications that are functionally similar to modern OLAP-systems.
Features
The key OLAP features usually are:
 Data views in multidimensional manner;
 Complex calculations support;
 Time intelligence;
 Easy-to-use interface.

So, there are about nine different OLAP types, but we can distinguish three main:
1. ROLAP
Relational OLAP are the systems that have direct access to existing relational databases or use data
uploaded to their own local tables. ROLAP works in the following way: The system sends the query
to a relational database – the required data turns back The key benefit of this system is that the
questions’ number is not limited as there are no boundaries generated by the cube content. It is also
possible to drill down in detail to the database lowest level. Also, relational DBMS provide security
and administration.

2. MOLAP
Multidimensional OLAP in comparison with previous type stores data in multidimensional database.
It means I is possible to manipulate data as a multidimensional array, so that the speed of calculating
aggregate values is the same for any of the measurements. Multidimensional OLAP architecture
includes:
 MOLAP server
 Database server
 Front-end tool
MOLAP involves creation of an explicit, physically stored multidimensional cube (or several cubes)
with the execution of analytical queries only on them, without reference to the relational database.
In this case, the highest productivity is achieved.

3. HOLAP
Hybrid OLAP, as it is clear from the name, combines the features of both ROLAP and MOLAP.
Wherein, HOLAP uses advantages of both and minimize disadvantages. Talking about Hybrid OLAP
architecture, the cube structure and pre-computed aggregates are stored in a multidimensional
database. It promotes rapid extraction of aggregates from MOLAP structures. The lower-level values
of the hierarchy in HOLAP remain in the relational data mart, which serves as the data source for the
cube. Some other OLAP types are:
 WOLAP (Web OLAP) – a three-tier architecture includes client, middleware and database
server. The access through web browser.
 SOLAP (Spatial OLAP) – combines possibilities of standard OLAP and Geographic Information
Systems in one UI.
 DOLAP (Desktop OLAP) – provides opportunity to work with dataset on user’s desktop. To do
that it is just necessary to download data from the source.
 Mobile OLAP - related to wireless networks or mobile devices. Mobile OLAP implementation
allows you to work with OLAP data and applications remotely via mobile devices.

Uses of OLAP
OLAP can be used for data mining or the discovery of previously undiscerned relationships between
data items. An OLAP database does not need to be as large as a data warehouse, since not all
transactional data is needed for trend analysis. Using Open Database Connectivity (ODBC), data can
be imported from existing relational databases to create a multidimensional database for OLAP.

OLAP products include IBM Cognos, Oracle OLAP and Oracle Essbase. OLAP features are also
included in tools such as Microsoft Excel and Microsoft SQL Server's Analysis Services). OLAP
products are typically designed for multiple-user environments, with the cost of the software based
on the number of users.

OLAP stands for Online Analytical Processing Server. It is a software technology that allows users to


analyze information from multiple database systems at the same time. It is based on
multidimensional data model and allows the user to query on multi-dimensional data (eg. Delhi ->
2018 -> Sales data). OLAP databases are divided into one or more cubes and these cubes are known
as Hyper-cubes.

OLAP operations:

There are five basic analytical operations that can be performed on an OLAP cube:

Drill down: In drill-down operation, the less detailed data is converted into highly detailed data. It
can be done by:

Moving down in the concept hierarchy

Adding a new dimension

In the cube given in overview section, the drill down operation is performed by moving down in the
concept hierarchy of Time dimension (Quarter -> Month).
Roll up: It is just opposite of the drill-down operation. It performs aggregation on the OLAP cube. It
can be done by:

Climbing up in the concept hierarchy

Reducing the dimensions

In the cube given in the overview section, the roll-up operation is performed by climbing up in the
concept hierarchy of Location dimension (City -> Country).

Dice: It selects a sub-cube from the OLAP cube by selecting two or more dimensions. In the cube
given in the overview section, a sub-cube is selected by selecting following dimensions with criteria:

Location = “Delhi” or “Kolkata”

Time = “Q1” or “Q2”

Item = “Car” or “Bus”


Slice: It selects a single dimension from the OLAP cube which results in a new sub-cube creation. In
the cube given in the overview section, Slice is performed on the dimension Time = “Q1”.

Pivot: It is also known as rotation operation as it rotates the current view to get a new view of the
representation. In the sub-cube obtained after the slice operation, performing pivot operation gives
a new view of it.

Demonstration of OLAP operations in sql


1) The CUBE operator computes a union of GROUP BY’s on every subset of the specified
attribute types.  Its result set represents a multidimensional cube based upon the source
table.  Consider the following SALES TABLE.
PRODUC
QUARTER REGION SALES
T
A Q1 Europe 10
A Q1 America 20
A Q2 Europe 20
A Q2 America 50
A Q3 America 20
A Q4 Europe 10
A Q4 America 30
B Q1 Europe 40
B Q1 America 60
B Q2 Europe 20
B Q2 America 10
B Q3 America 20
B Q4 Europe 10
B Q4 America 40

We can now formulate the following SQL query:

SELECT QUARTER, REGION, SUM(SALES)


FROM SALESTABLE
GROUP BY CUBE (QUARTER, REGION)

SELECT CASE WHEN grouping(QUARTER) = 1 THEN 'All' ELSE QUARTER END AS QUARTER, CASE WHEN
grouping(REGION) = 1 THEN 'All' ELSE REGION END AS REGION, SUM(SALES)
FROM SALESTABLE
GROUP BY CUBE (QUARTER, REGION)
The grouping() function returns 1 in case a NULL value is generated during the aggregation
and 0 otherwise.  This distinguishes the generated NULLs and the possible real NULLs
stemming from the data.  We will not add this to the subsequent OLAP queries so as to not
unnecessarily complicate them.

QUARTER REGION SALES


Q1 Europe 50
Q1 America 80
Q2 Europe 40
Q2 America 60
Q3 Europe NULL
Q3 America 40
Q4 Europe 20
Q4 America 80
Q1 NULL 130
Q2 NULL 100
Q3 NULL 40
Q4 NULL 90
NULL Europe 110
NULL America 250
NULL NULL 360
Table 1: Result from SQL query with Cube operator.

2) The ROLLUP operator computes the union on every prefix of the list of specified attribute
types, from the most detailed up to the grand total.  It is especially useful to generate
reports containing both subtotals and totals.  The key difference between the ROLLUP and
CUBE operator is that the former generates a result set showing the aggregates for a
hierarchy of values of the specified attribute types, whereas the latter generates a result set
showing the aggregates for all combinations of values of the selected attribute types. 
Hence, the order in which the attribute types are mentioned is important for the ROLLUP
but not for the CUBE operator. 

SELECT QUARTER, REGION, SUM(SALES)


FROM SALESTABLE
GROUP BY ROLLUP (QUARTER, REGION)
QUARTER REGION SALES
Q1 Europe 50
Q1 America 80
Q2 Europe 40
Q2 America 60
Q3 Europe NULL
Q3 America 40
Q4 Europe 20
Q4 America 80
Q1 NULL 130
Q2 NULL 100
Q3 NULL 40
Q4 NULL 90
NULL NULL 360
Table 2: Result from SQL query with ROLLUP operator.

The GROUPING SETS operator generates a result set equivalent to that generated by a


UNION ALL of multiple simple GROUP BY clauses.  Consider the following example:

SELECT QUARTER, REGION, SUM(SALES)


FROM SALESTABLE
GROUP BY GROUPING SETS ((QUARTER), (REGION))
This query is equivalent to:

SELECT QUARTER, NULL, SUM(SALES)


FROM SALESTABLE
GROUP BY QUARTER
UNION ALL
SELECT NULL, REGION, SUM(SALES)
FROM SALESTABLE
GROUP BY REGION
The result is given in Table 3.

QUARTER REGION SALES


Q1 NULL 130
Q2 NULL 100
Q3 NULL 40
Q4 NULL 90
NULL Europe 110
NULL America 250
Table 3: Result from SQL query with GROUPING SETS operator

You might also like