SlideShare a Scribd company logo
1 of 13
Download to read offline
SQL OLAP Querying
Question:
Which customer has bought the most of each product we sell? Show
the product ID and description, customer ID and name, and the total
quantity sold of that product to that customer; show the results in
sequence by product ID.
Query:
SELECT P1.ProductId, ProductDescription, C1.CustomerId,
CustomerName,SUM(OL1.OrderedQuantity) AS TotOrdered FROM
Customer_T AS C1, Product_T AS P1, OrderLine_T AS OL1, Order_T AS
O1 WHERE C1.CustomerId = O1.CustomerId AND O1.OrderId =
OL1.OrderId AND OL1.ProductId = P1.ProductId GROUP BY
P1.ProductId, ProductDescription, C1.CustomerId, CustomerName
HAVING TotOrdered >= ALL (SELECT SUM(OL2.OrderedQuantity) FROM
OrderLine_T AS OL2, Order_T AS O2 WHERE OL2.ProductId =
P1.ProductId AND OL2.OrderId = O2.OrderId AND O2.CustomerId <>
C1.CustomerId GROUP BY O2.CustomerId) ORDER BY P1.ProductId;
Note:
Some versions of SQL support special clauses that make ranking
questions easier to write. For example, Microsoft SQL Server and some
other RDBMSs support clauses of FIRST n, TOP n, LAST n, and BOTTOM
n rows. Thus, the query shown previously could be greatly simplified by
adding TOP 1 in front of the SUM in the outer query and eliminating
the HAVING and subquery.
Recent versions of SQL include some data warehousing and business
intelligence extensions. Because many data warehousing operations
deal with categories of objects, possibly ordered by date, the SQL
standard includes a WINDOW clause to define dynamic sets of rows. (In
many SQL systems, the word OVER is used instead of WINDOW, which
is what we illustrate next.)
For example,
An OVER clause can be used to define three adjacent days as the basis
for calculating moving averages. (Think of a window moving between
the bottom and top of its window frame, giving you a sliding view of
rows of data.) PARTITION BY within an OVER clause is similar to GROUP
BY; PARTITION BY tells an OVER clause the basis for each set, an ORDER
BY clause sequences the elements of a set, and the ROWS clause says
how many rows in sequence to use in a calculation.
For example, consider a SalesHistory table (columns TerritoryID,
Quarter, and Sales) and the desire to show a three-quarter moving
average of sales. The following SQL will produce the desired result
using these OLAP clauses:
SELECT TerritoryID, Quarter, Sales, AVG(Sales) OVER (PARTITION BY
TerritoryID ORDER BY Quarter ROWS 2 PRECEDING) AS 3QtrAverage
FROM SalesHistory;
The PARTITION BY clause groups the rows of the SalesHistory table by
TerritoryID for the purpose of computing 3QtrAverage, and then the
ORDER BY clause sorts by quarter within these groups. The ROWS
clause indicates how many rows over which to calculate the AVG(Sales).
The following is a sample of the results from this query:
OLAP Tools
A specialized class of tools has been developed to provide users with
multidimensional views of their data. Such tools also usually offer users
a graphical interface so that they can easily analyze their data. In the
simplest case, data are viewed as a simple three-dimensional cube.
Online analytical processing (OLAP) is the use of a set of query and
reporting tools that provides users with multidimensional views of their
data and allows them to analyze the data using simple windowing
techniques.
The term multidimensional analysis is often used as a synonym for
OLAP.
An example of a “data cube” (or multidimensional view) of data that is
typical of OLAP is shown below.
ROLAP
OLAP tools that view the database as a traditional relational database
in either a star schema or other normalized or denormalized set of
tables.
ROLAP tools access the data warehouse or data mart directly.
MOLAP
OLAP tools that load data into an intermediate structure, usually a three- or
higher-dimensional array.
Multidimensional OLAP (MOLAP) tools load data into an intermediate
structure, usually a three- or higher-dimensional array (hypercube). It is
important to note with MOLAP that the data are not simply viewed as a
multidimensional hypercube, but rather a MOLAP data mart is created by
extracting data from the data warehouse or data mart and then storing the
data in a specialized separate data store through which data can be viewed
only through a multidimensional structure. Other, less-common categories of
OLAP tools are database OLAP (DOLAP), which includes OLAP functionality in
the DBMS query language (there are proprietary, non-ANSI standard SQL
systems that do this), and hybrid OLAP (HOLAP), which allows access via both
multidimensional cubes or relational query languages.
Slicing a Cube
Figure 9-21 shows a typical MOLAP operation: slicing the data cube to
produce a simple two-dimensional table or view. In Figure 9-21, this
slice is for the product named shoes. The resulting table shows the
three measures (units, revenues, and cost) for this product by period
(or month). Other views can easily be developed by the user by means
of simple “drag and drop” operations. This type of operation is often
called slicing and dicing the cube.

More Related Content

Similar to (Lecture 5)OLAP Querying.pdf

Oracle_Analytical_function.pdf
Oracle_Analytical_function.pdfOracle_Analytical_function.pdf
Oracle_Analytical_function.pdfKalyankumarVenkat1
 
UKOUG Tech14 - Using Database In-Memory Column Store with Complex Datatypes
UKOUG Tech14 - Using Database In-Memory Column Store with Complex DatatypesUKOUG Tech14 - Using Database In-Memory Column Store with Complex Datatypes
UKOUG Tech14 - Using Database In-Memory Column Store with Complex DatatypesMarco Gralike
 
Project report aditi paul1
Project report aditi paul1Project report aditi paul1
Project report aditi paul1guest9529cb
 
SQL – The Natural Language for Analysis - Oracle - Whitepaper - 2431343
SQL – The Natural Language for Analysis - Oracle - Whitepaper - 2431343SQL – The Natural Language for Analysis - Oracle - Whitepaper - 2431343
SQL – The Natural Language for Analysis - Oracle - Whitepaper - 2431343Edgar Alejandro Villegas
 
Database Architecture and Basic Concepts
Database Architecture and Basic ConceptsDatabase Architecture and Basic Concepts
Database Architecture and Basic ConceptsTony Wong
 
Oracle inventory R12 Setup Guide
Oracle inventory R12 Setup GuideOracle inventory R12 Setup Guide
Oracle inventory R12 Setup GuideAhmed Elshayeb
 
Intro To TSQL - Unit 4
Intro To TSQL - Unit 4Intro To TSQL - Unit 4
Intro To TSQL - Unit 4iccma
 
Intro to tsql unit 4
Intro to tsql   unit 4Intro to tsql   unit 4
Intro to tsql unit 4Syed Asrarali
 
Data ware house architecture
Data ware house architectureData ware house architecture
Data ware house architectureDeepak Chaurasia
 

Similar to (Lecture 5)OLAP Querying.pdf (20)

Abap
AbapAbap
Abap
 
Sql
SqlSql
Sql
 
Sql wksht-3
Sql wksht-3Sql wksht-3
Sql wksht-3
 
Oracle_Analytical_function.pdf
Oracle_Analytical_function.pdfOracle_Analytical_function.pdf
Oracle_Analytical_function.pdf
 
UKOUG Tech14 - Using Database In-Memory Column Store with Complex Datatypes
UKOUG Tech14 - Using Database In-Memory Column Store with Complex DatatypesUKOUG Tech14 - Using Database In-Memory Column Store with Complex Datatypes
UKOUG Tech14 - Using Database In-Memory Column Store with Complex Datatypes
 
Hive(ppt)
Hive(ppt)Hive(ppt)
Hive(ppt)
 
Hive(ppt)
Hive(ppt)Hive(ppt)
Hive(ppt)
 
Project report aditi paul1
Project report aditi paul1Project report aditi paul1
Project report aditi paul1
 
SQL Tunning
SQL TunningSQL Tunning
SQL Tunning
 
unit 1 ppt.pptx
unit 1 ppt.pptxunit 1 ppt.pptx
unit 1 ppt.pptx
 
SQL – The Natural Language for Analysis - Oracle - Whitepaper - 2431343
SQL – The Natural Language for Analysis - Oracle - Whitepaper - 2431343SQL – The Natural Language for Analysis - Oracle - Whitepaper - 2431343
SQL – The Natural Language for Analysis - Oracle - Whitepaper - 2431343
 
3 OLAP.pptx
3 OLAP.pptx3 OLAP.pptx
3 OLAP.pptx
 
Database Architecture and Basic Concepts
Database Architecture and Basic ConceptsDatabase Architecture and Basic Concepts
Database Architecture and Basic Concepts
 
Sql
SqlSql
Sql
 
Sql
SqlSql
Sql
 
Oracle inventory R12 Setup Guide
Oracle inventory R12 Setup GuideOracle inventory R12 Setup Guide
Oracle inventory R12 Setup Guide
 
Intro To TSQL - Unit 4
Intro To TSQL - Unit 4Intro To TSQL - Unit 4
Intro To TSQL - Unit 4
 
Intro to tsql unit 4
Intro to tsql   unit 4Intro to tsql   unit 4
Intro to tsql unit 4
 
Oracle SQL Basics
Oracle SQL BasicsOracle SQL Basics
Oracle SQL Basics
 
Data ware house architecture
Data ware house architectureData ware house architecture
Data ware house architecture
 

More from MobeenMasoudi

Purpose the of Process Modeling.pptx
Purpose the of Process Modeling.pptxPurpose the of Process Modeling.pptx
Purpose the of Process Modeling.pptxMobeenMasoudi
 
Purpose of Process Modeling.pptx
Purpose of Process Modeling.pptxPurpose of Process Modeling.pptx
Purpose of Process Modeling.pptxMobeenMasoudi
 
Process Modeling.pptx
Process Modeling.pptxProcess Modeling.pptx
Process Modeling.pptxMobeenMasoudi
 
Flow Charting – Disadvantages.pptx
Flow Charting – Disadvantages.pptxFlow Charting – Disadvantages.pptx
Flow Charting – Disadvantages.pptxMobeenMasoudi
 
Commonly Used Process Modeling Notations.pptx
Commonly Used Process Modeling Notations.pptxCommonly Used Process Modeling Notations.pptx
Commonly Used Process Modeling Notations.pptxMobeenMasoudi
 
Data Warehousing Overview.pptx
Data Warehousing Overview.pptxData Warehousing Overview.pptx
Data Warehousing Overview.pptxMobeenMasoudi
 
Himmatullah Ferozee Assingnment.pptx
Himmatullah Ferozee Assingnment.pptxHimmatullah Ferozee Assingnment.pptx
Himmatullah Ferozee Assingnment.pptxMobeenMasoudi
 
E-A Assessing the value of enterprise architecture.pptx
E-A Assessing the value of enterprise architecture.pptxE-A Assessing the value of enterprise architecture.pptx
E-A Assessing the value of enterprise architecture.pptxMobeenMasoudi
 
(Lecture 4)Slowly Changing Dimensions.pdf
(Lecture 4)Slowly Changing Dimensions.pdf(Lecture 4)Slowly Changing Dimensions.pdf
(Lecture 4)Slowly Changing Dimensions.pdfMobeenMasoudi
 
(Lecture 3) Star Schema.pdf
(Lecture 3) Star Schema.pdf(Lecture 3) Star Schema.pdf
(Lecture 3) Star Schema.pdfMobeenMasoudi
 
(Lecture 2)Data Warehouse Architecture.pdf
(Lecture 2)Data Warehouse Architecture.pdf(Lecture 2)Data Warehouse Architecture.pdf
(Lecture 2)Data Warehouse Architecture.pdfMobeenMasoudi
 
(Lecture 1)Data Warehousing Overview.pdf
(Lecture 1)Data Warehousing Overview.pdf(Lecture 1)Data Warehousing Overview.pdf
(Lecture 1)Data Warehousing Overview.pdfMobeenMasoudi
 

More from MobeenMasoudi (15)

Purpose the of Process Modeling.pptx
Purpose the of Process Modeling.pptxPurpose the of Process Modeling.pptx
Purpose the of Process Modeling.pptx
 
Purpose of Process Modeling.pptx
Purpose of Process Modeling.pptxPurpose of Process Modeling.pptx
Purpose of Process Modeling.pptx
 
Process Modeling.pptx
Process Modeling.pptxProcess Modeling.pptx
Process Modeling.pptx
 
Flow Charting – Disadvantages.pptx
Flow Charting – Disadvantages.pptxFlow Charting – Disadvantages.pptx
Flow Charting – Disadvantages.pptx
 
Commonly Used Process Modeling Notations.pptx
Commonly Used Process Modeling Notations.pptxCommonly Used Process Modeling Notations.pptx
Commonly Used Process Modeling Notations.pptx
 
BPModeling1.pptx
BPModeling1.pptxBPModeling1.pptx
BPModeling1.pptx
 
BPMN 2.pptx
BPMN 2.pptxBPMN 2.pptx
BPMN 2.pptx
 
chapter1.pptx
chapter1.pptxchapter1.pptx
chapter1.pptx
 
Data Warehousing Overview.pptx
Data Warehousing Overview.pptxData Warehousing Overview.pptx
Data Warehousing Overview.pptx
 
Himmatullah Ferozee Assingnment.pptx
Himmatullah Ferozee Assingnment.pptxHimmatullah Ferozee Assingnment.pptx
Himmatullah Ferozee Assingnment.pptx
 
E-A Assessing the value of enterprise architecture.pptx
E-A Assessing the value of enterprise architecture.pptxE-A Assessing the value of enterprise architecture.pptx
E-A Assessing the value of enterprise architecture.pptx
 
(Lecture 4)Slowly Changing Dimensions.pdf
(Lecture 4)Slowly Changing Dimensions.pdf(Lecture 4)Slowly Changing Dimensions.pdf
(Lecture 4)Slowly Changing Dimensions.pdf
 
(Lecture 3) Star Schema.pdf
(Lecture 3) Star Schema.pdf(Lecture 3) Star Schema.pdf
(Lecture 3) Star Schema.pdf
 
(Lecture 2)Data Warehouse Architecture.pdf
(Lecture 2)Data Warehouse Architecture.pdf(Lecture 2)Data Warehouse Architecture.pdf
(Lecture 2)Data Warehouse Architecture.pdf
 
(Lecture 1)Data Warehousing Overview.pdf
(Lecture 1)Data Warehousing Overview.pdf(Lecture 1)Data Warehousing Overview.pdf
(Lecture 1)Data Warehousing Overview.pdf
 

Recently uploaded

Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdfankushspencer015
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSSIVASHANKAR N
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Call Girls in Nagpur High Profile
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxupamatechverse
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxAsutosh Ranjan
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur Escorts
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur EscortsRussian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur Escorts
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSISrknatarajan
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performancesivaprakash250
 
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxBSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxfenichawla
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxupamatechverse
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)simmis5
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdfKamal Acharya
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Christo Ananth
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Bookingdharasingh5698
 

Recently uploaded (20)

Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptx
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur Escorts
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur EscortsRussian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur Escorts
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur Escorts
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSIS
 
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxBSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdf
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
 

(Lecture 5)OLAP Querying.pdf

  • 2. Question: Which customer has bought the most of each product we sell? Show the product ID and description, customer ID and name, and the total quantity sold of that product to that customer; show the results in sequence by product ID.
  • 3. Query: SELECT P1.ProductId, ProductDescription, C1.CustomerId, CustomerName,SUM(OL1.OrderedQuantity) AS TotOrdered FROM Customer_T AS C1, Product_T AS P1, OrderLine_T AS OL1, Order_T AS O1 WHERE C1.CustomerId = O1.CustomerId AND O1.OrderId = OL1.OrderId AND OL1.ProductId = P1.ProductId GROUP BY P1.ProductId, ProductDescription, C1.CustomerId, CustomerName HAVING TotOrdered >= ALL (SELECT SUM(OL2.OrderedQuantity) FROM OrderLine_T AS OL2, Order_T AS O2 WHERE OL2.ProductId = P1.ProductId AND OL2.OrderId = O2.OrderId AND O2.CustomerId <> C1.CustomerId GROUP BY O2.CustomerId) ORDER BY P1.ProductId;
  • 4. Note: Some versions of SQL support special clauses that make ranking questions easier to write. For example, Microsoft SQL Server and some other RDBMSs support clauses of FIRST n, TOP n, LAST n, and BOTTOM n rows. Thus, the query shown previously could be greatly simplified by adding TOP 1 in front of the SUM in the outer query and eliminating the HAVING and subquery.
  • 5. Recent versions of SQL include some data warehousing and business intelligence extensions. Because many data warehousing operations deal with categories of objects, possibly ordered by date, the SQL standard includes a WINDOW clause to define dynamic sets of rows. (In many SQL systems, the word OVER is used instead of WINDOW, which is what we illustrate next.)
  • 6. For example, An OVER clause can be used to define three adjacent days as the basis for calculating moving averages. (Think of a window moving between the bottom and top of its window frame, giving you a sliding view of rows of data.) PARTITION BY within an OVER clause is similar to GROUP BY; PARTITION BY tells an OVER clause the basis for each set, an ORDER BY clause sequences the elements of a set, and the ROWS clause says how many rows in sequence to use in a calculation.
  • 7. For example, consider a SalesHistory table (columns TerritoryID, Quarter, and Sales) and the desire to show a three-quarter moving average of sales. The following SQL will produce the desired result using these OLAP clauses: SELECT TerritoryID, Quarter, Sales, AVG(Sales) OVER (PARTITION BY TerritoryID ORDER BY Quarter ROWS 2 PRECEDING) AS 3QtrAverage FROM SalesHistory;
  • 8. The PARTITION BY clause groups the rows of the SalesHistory table by TerritoryID for the purpose of computing 3QtrAverage, and then the ORDER BY clause sorts by quarter within these groups. The ROWS clause indicates how many rows over which to calculate the AVG(Sales). The following is a sample of the results from this query:
  • 9. OLAP Tools A specialized class of tools has been developed to provide users with multidimensional views of their data. Such tools also usually offer users a graphical interface so that they can easily analyze their data. In the simplest case, data are viewed as a simple three-dimensional cube. Online analytical processing (OLAP) is the use of a set of query and reporting tools that provides users with multidimensional views of their data and allows them to analyze the data using simple windowing techniques. The term multidimensional analysis is often used as a synonym for OLAP.
  • 10. An example of a “data cube” (or multidimensional view) of data that is typical of OLAP is shown below.
  • 11. ROLAP OLAP tools that view the database as a traditional relational database in either a star schema or other normalized or denormalized set of tables. ROLAP tools access the data warehouse or data mart directly.
  • 12. MOLAP OLAP tools that load data into an intermediate structure, usually a three- or higher-dimensional array. Multidimensional OLAP (MOLAP) tools load data into an intermediate structure, usually a three- or higher-dimensional array (hypercube). It is important to note with MOLAP that the data are not simply viewed as a multidimensional hypercube, but rather a MOLAP data mart is created by extracting data from the data warehouse or data mart and then storing the data in a specialized separate data store through which data can be viewed only through a multidimensional structure. Other, less-common categories of OLAP tools are database OLAP (DOLAP), which includes OLAP functionality in the DBMS query language (there are proprietary, non-ANSI standard SQL systems that do this), and hybrid OLAP (HOLAP), which allows access via both multidimensional cubes or relational query languages.
  • 13. Slicing a Cube Figure 9-21 shows a typical MOLAP operation: slicing the data cube to produce a simple two-dimensional table or view. In Figure 9-21, this slice is for the product named shoes. The resulting table shows the three measures (units, revenues, and cost) for this product by period (or month). Other views can easily be developed by the user by means of simple “drag and drop” operations. This type of operation is often called slicing and dicing the cube.