SlideShare a Scribd company logo
1 of 28
Download to read offline
DataWarehouses,
OLAP, and the
CUBE operator
Jake Lear, Scott Fabini
CS586 -Winter 2015
OLTP/OLAP Comparison
OLAP: On-Line
Analytic Processing
OLTP: On-Line
Transaction Processing
OLTP Query for A Single
Sales Order in an SAP DB
OLAP Query for revenue
by Geography / Product-
Line in an IBM Cognos DB
OLTP/OLAP Comparison
OLTP
• Simple, frequent queries
• Up-to-the-minute information
• Fast response time needed
OLAP
• Few queries, but very complex
• Lots of indexes
• May run for hours
• Doesn’t need up-to-the-minute
info
OLTP Queries
OLAP Query
Animation
OLAP Queries on a DB
OLAP Queries
• We have a long-running transaction
analyzing all sales data.
• What about the new sales data
coming into the database while our
transaction is running?
• Talk to your neighbor. Think in
terms of serializable transactions
and locking mechanisms…
• Recall, Reads get an S-Lock.
Writers forbidden from
getting their X-Lock
StalledTransactions!
Animation
OLAP
DataWarehouse
OLTP
Database
Copy
Over
night
Support fast transactions
Dedicated for Analytics of
Aggregate Data
Animation
The DataWarehouse Congregates
Multiple Data Sources
CRM
SCP
ERP
DataWarehouse
Supply Chain
(Vendor) Data
Factory
Planning Data
Sales/
Marketing Data
OLAP Queries
What is our worst-selling vehicle?
Do we need another factory to meet demand?
Should we focus sales on Europe or Japan?
Summarizing the
Motivation for OLAP
• We want to add lots of Indexes for faster search, and perform
long-running transactions, but this slows down the DB
• We only need to look at the long term trends, not up-to-the-
second data
• We may want to aggregate data from multiple DBs
• Answer: Move the data to a DataWarehouse for targeted
analysis. Use OLAP techniques which we learn today to slice
& dice the massive aggregate into discrete actionable data.
Auto Sales Example
• Say we want to record in a data warehouse all auto sales
• We would create aTable with key info for the sale
• Serial Number, Dealer Name, Date of Sale, Price of Sale
• The relation becomes our FactTable:
• sales(auto, dealer, date, price)
Visualizing Multidimensional
Data
• FactTable: a central
relation or collection
of data
• E.g. all information
about a sale of an
automobile
• Dimensions:
Represent the
properties of the sale
Dealer
Days
Auto
Dealer
Auto
Dicing the Data
• The FactTable is ‘diced’
(divided) by its dimensions
- the DimensionTables
Date
Boring Barney’s
WittyWilma’s
Friendly Fred’s
Gobi
Aardvark
200120022003200420052006
Price
Dependent
AttributesDimension attributes
AutoDealerDate
ColorModelSerial#
Phone#CityNameYearMonthDay
Dealer Dimension
Auto Dimension
Days Dimension
Price
Sales FactTable
Implementation: Star Schema
Date
Dimension
allows us to
aggregate by
year, month,
or week
Dealer
Dimension
allows us to
aggregate by
dealer
Auto
Dimension
allows us to
aggregate by
Model or Color
Animation
Dependent
Attributes help
group Aggregate
data, (like sum of
prices of autos
sold)
-
Working within a Star Schema
• A Star Schema example can be found in my personal
‘sfabini’ CAT database
• Connect by issuing the following command:
Please do not alter the database
ColorModelSerial#
Phone#CityName
YearMonthDay
Dealer Dimension
Auto Dimension
Days Dimension
Price
Implementation: Star Schema
Dimensions
-
Price
Dependent
AttributesDimension attributes
Auto DealerDate
ColorModelSerial# Phone#CityName
YearMonthDay
Dealer DimensionAuto Dimension
Date Dimension
Price
Sales FactTable
Implementation: Star Schema
FactTable
-
Dealer
Auto
Dicing the Data
• Recapping, does everyone see
the ‘dimensions’ and how
they divide the FactTable?
• Date divided along x axis
• Different dealers on y axis
• Different autos on z axis
• Within the cube (fact table) are
the dots -- individual auto sales,
including how much it sold for
(price)
Date
Boring Barney’s
WittyWilma’s
Friendly Fred’s
Gobi
Aardvark
200120022003200420052006
Dealer
Auto
Exercise: Slicing the Data
• Find Average Sales Price
by State
SELECT state, AVG(price)
FROM sales, dealers
WHERE sales.dealer =
dealer.name
GROUP BY state;
Date
Boring Barney’s
WittyWilma’s
Arizona
New
M
exico
Friendly Fred’s
Try it yourself!
Which state’s dealers maximize ASP
(average selling price)?
Dealer
Auto
Exercise: Drilling Down
• FindTotal Sales Price for Gobis at
Friendly Fred’s
SELECT color, SUM(price)
FROM sales,
NATURAL JOIN autos
JOIN dealer ON name = sales.dealer
WHERE sales.dealer = ‘Friendly Fred’
AND
Model = ‘Gobi’
GROUP BY color;
Date
Boring Barney’s
WittyWilma’s
Arizona
New
M
exico
Friendly Fred’s
Try it yourself!
Joining tables in your query, and then
Grouping ‘drills down’ the table
Rolling Up and Drilling Down
• Drill-Down: Focusing on specific values in certain
dimensions
• looking at the sales of red Gobis at Friendly Fred’s
• Roll-Up: Aggregate along one or more dimensions
• Looking at all colors as groups to find the best selling color overall
Foundations of the CUBE
Operator
Dealer
Date
Auto
Sum of price of
all autos, by a
specific dealer,
on all dates
Sum of price of a
specific auto, by a
specific dealer, on
all datesPrice of a specific
auto, by a specific
dealer, on a
specific date
The Cube
operator adds a
border of
aggregations to
the data cube
across all
combinations of
dimensions.
Sum of price of all
autos, by all
dealers, on all
dates
CUBE vs. ROLLUP Operators
• WITH CUBE: If we add the termWITH CUBE to a group-by
clause, then we get not only the tuples for the group , but
also the tuples that represent aggregation along one or
more dimensions along which we have grouped
• WITH ROLLUP: A variant of the CUBE operator that
produces the additional aggregated tuples over the tail of
the sequence of grouping attributes
Working with a Cube and
phpMyAdmin
• We need to use MySQL to demonstrate Cube/Rollup
• A Cube example can be found in my personal ‘sfabini’ CAT
database
• Connect via website: cat.pdx.edu/phpMyAdmin/
Working with a Cube
• We need to use MySQL to demonstrate Cube/Rollup
• A Cube example can be found in my personal ‘sfabini’ CAT
database
• Connect by issuing the following command:
ROLLUP Query in MySQL
• SELECT model, color, DATE, dealer, SUM( val ) , 
SUM( cnt ) 
FROM SalesCube
GROUP BY model, color, DATE, dealer
WITH ROLLUP
Results: Auto SalesWITH ROLLUP
in MySQL
Aggregate of blue Gobis sold
Aggregate of red Gobis sold
Aggregate of all Gobis sold
Aggregate of all cars sold
Aggregate of red Gobis sold by any dealer on this date
CUBE Query in SQL99
• SELECT model, color, DATE, dealer, SUM( val ) , 
SUM( cnt ) 
FROM SalesCube
GROUP BY model, color, DATE, dealer
WITH CUBE
• CUBE Query Result (Partial):
• Rollup Query Result:
Comparison:WITH ROLLUP vs.
WITH CUBE results
All colors of Gobis sold at Friendly Fred’s on 5/21
Aggregate of all Gobis sold
Aggregate of all autos sold
Aggregate of all Gobi sales by any dealer on 5/21
… all such combinations are listedWITH CUBE
Red Gobis sold at Friendly Fred’s on 5/21
Red Gobis sold at any dealer on 5/21
Red Gobis sold at any dealer on any date
Any Gobi sold at any dealer on any date
Aggregate of all autos sold
Homework
• 1a) Use the ‘sfabini’ mysql db to answer Exercise 10.7.2 (a)
and (b) from the book
• Notes:
• Execute your query FROM the SalesCube table
• Use theWITH ROLLUP operator, instead ofWITH CUBE
• Smilin Sally is spelled without the apostrophe in the DB
• See Example 10.33 for further hints on usingWITH ROLLUP

More Related Content

Viewers also liked

FedX - Optimization Techniques for Federated Query Processing on Linked Data
FedX - Optimization Techniques for Federated Query Processing on Linked DataFedX - Optimization Techniques for Federated Query Processing on Linked Data
FedX - Optimization Techniques for Federated Query Processing on Linked Dataaschwarte
 
Whats A Data Warehouse
Whats A Data WarehouseWhats A Data Warehouse
Whats A Data WarehouseNone None
 
Oracle Optimizer: 12c New Capabilities
Oracle Optimizer: 12c New CapabilitiesOracle Optimizer: 12c New Capabilities
Oracle Optimizer: 12c New CapabilitiesGuatemala User Group
 
Materialized views in PostgreSQL
Materialized views in PostgreSQLMaterialized views in PostgreSQL
Materialized views in PostgreSQLAshutosh Bapat
 
Nata de Coco Management Case
Nata de Coco Management CaseNata de Coco Management Case
Nata de Coco Management Caserogel84
 
Cassandra Materialized Views
Cassandra Materialized ViewsCassandra Materialized Views
Cassandra Materialized ViewsCarl Yeksigian
 
SSSW2015 Data Workflow Tutorial
SSSW2015 Data Workflow TutorialSSSW2015 Data Workflow Tutorial
SSSW2015 Data Workflow TutorialSSSW
 
Thesis: Slicing of Java Programs using the Soot Framework (2006)
Thesis:  Slicing of Java Programs using the Soot Framework (2006) Thesis:  Slicing of Java Programs using the Soot Framework (2006)
Thesis: Slicing of Java Programs using the Soot Framework (2006) Arvind Devaraj
 
Case Study Real Time Olap Cubes
Case Study Real Time Olap CubesCase Study Real Time Olap Cubes
Case Study Real Time Olap Cubesmister_zed
 
Crm evolution- crm phases
Crm  evolution- crm phasesCrm  evolution- crm phases
Crm evolution- crm phaseshemchandmba14
 
OLAP Cubes: Basic operations
OLAP Cubes: Basic operationsOLAP Cubes: Basic operations
OLAP Cubes: Basic operationsSthefan Berwanger
 
Design, Fabrication and Analysis of Crank and Slotted Lever Quick Return Mech...
Design, Fabrication and Analysis of Crank and Slotted Lever Quick Return Mech...Design, Fabrication and Analysis of Crank and Slotted Lever Quick Return Mech...
Design, Fabrication and Analysis of Crank and Slotted Lever Quick Return Mech...Mohammed Naseeruddin Shah
 
MS SQL SERVER: Olap cubes and data mining
MS SQL SERVER: Olap cubes and data miningMS SQL SERVER: Olap cubes and data mining
MS SQL SERVER: Olap cubes and data miningDataminingTools Inc
 
Cassandra and materialized views
Cassandra and materialized viewsCassandra and materialized views
Cassandra and materialized viewsGrzegorz Duda
 
OLAP & DATA WAREHOUSE
OLAP & DATA WAREHOUSEOLAP & DATA WAREHOUSE
OLAP & DATA WAREHOUSEZalpa Rathod
 

Viewers also liked (17)

FedX - Optimization Techniques for Federated Query Processing on Linked Data
FedX - Optimization Techniques for Federated Query Processing on Linked DataFedX - Optimization Techniques for Federated Query Processing on Linked Data
FedX - Optimization Techniques for Federated Query Processing on Linked Data
 
Whats A Data Warehouse
Whats A Data WarehouseWhats A Data Warehouse
Whats A Data Warehouse
 
Oracle Optimizer: 12c New Capabilities
Oracle Optimizer: 12c New CapabilitiesOracle Optimizer: 12c New Capabilities
Oracle Optimizer: 12c New Capabilities
 
Materialized views in PostgreSQL
Materialized views in PostgreSQLMaterialized views in PostgreSQL
Materialized views in PostgreSQL
 
Nata de Coco Management Case
Nata de Coco Management CaseNata de Coco Management Case
Nata de Coco Management Case
 
Cassandra Materialized Views
Cassandra Materialized ViewsCassandra Materialized Views
Cassandra Materialized Views
 
SSSW2015 Data Workflow Tutorial
SSSW2015 Data Workflow TutorialSSSW2015 Data Workflow Tutorial
SSSW2015 Data Workflow Tutorial
 
Thesis: Slicing of Java Programs using the Soot Framework (2006)
Thesis:  Slicing of Java Programs using the Soot Framework (2006) Thesis:  Slicing of Java Programs using the Soot Framework (2006)
Thesis: Slicing of Java Programs using the Soot Framework (2006)
 
Case Study Real Time Olap Cubes
Case Study Real Time Olap CubesCase Study Real Time Olap Cubes
Case Study Real Time Olap Cubes
 
Crm evolution- crm phases
Crm  evolution- crm phasesCrm  evolution- crm phases
Crm evolution- crm phases
 
OLAP Cubes: Basic operations
OLAP Cubes: Basic operationsOLAP Cubes: Basic operations
OLAP Cubes: Basic operations
 
OLAP
OLAPOLAP
OLAP
 
Design, Fabrication and Analysis of Crank and Slotted Lever Quick Return Mech...
Design, Fabrication and Analysis of Crank and Slotted Lever Quick Return Mech...Design, Fabrication and Analysis of Crank and Slotted Lever Quick Return Mech...
Design, Fabrication and Analysis of Crank and Slotted Lever Quick Return Mech...
 
MS SQL SERVER: Olap cubes and data mining
MS SQL SERVER: Olap cubes and data miningMS SQL SERVER: Olap cubes and data mining
MS SQL SERVER: Olap cubes and data mining
 
OLAP
OLAPOLAP
OLAP
 
Cassandra and materialized views
Cassandra and materialized viewsCassandra and materialized views
Cassandra and materialized views
 
OLAP & DATA WAREHOUSE
OLAP & DATA WAREHOUSEOLAP & DATA WAREHOUSE
OLAP & DATA WAREHOUSE
 

Similar to Data Warehouse and OLAP - Lear-Fabini

4th Auto Remarketing Forum India 2017
4th Auto Remarketing Forum India 20174th Auto Remarketing Forum India 2017
4th Auto Remarketing Forum India 2017Ilana Kearns
 
Building a semantic/metrics layer using Calcite
Building a semantic/metrics layer using CalciteBuilding a semantic/metrics layer using Calcite
Building a semantic/metrics layer using CalciteJulian Hyde
 
Running Complex Sourcing Events – A Best Practices Approach
Running Complex Sourcing Events – A Best Practices ApproachRunning Complex Sourcing Events – A Best Practices Approach
Running Complex Sourcing Events – A Best Practices ApproachSAP Ariba
 
Increase auto dealership sales
Increase auto dealership sales Increase auto dealership sales
Increase auto dealership sales dalelama
 
Content Commerce + Growth Strategies For Online Retailers
Content Commerce + Growth Strategies For Online RetailersContent Commerce + Growth Strategies For Online Retailers
Content Commerce + Growth Strategies For Online RetailersRoland Frasier
 
Cdm presentation 10-2010
Cdm presentation  10-2010Cdm presentation  10-2010
Cdm presentation 10-2010djk1976djk
 
Writing Ads for Autos Classified Sites That Work
Writing Ads for Autos Classified Sites That WorkWriting Ads for Autos Classified Sites That Work
Writing Ads for Autos Classified Sites That Workrythompson
 
2 day ism workshop v1.1
2 day ism workshop v1.12 day ism workshop v1.1
2 day ism workshop v1.1Ralph Paglia
 
10+ ways to get MORE from Google Analytics
10+ ways to get MORE from Google Analytics10+ ways to get MORE from Google Analytics
10+ ways to get MORE from Google AnalyticsTim Stewart
 
Automotive Syndication
Automotive SyndicationAutomotive Syndication
Automotive Syndicationkleinkak
 
DMSS: SEO Insights, Analysis & Reporting: Visualizing Your SEO Data
DMSS: SEO Insights, Analysis & Reporting: Visualizing Your SEO DataDMSS: SEO Insights, Analysis & Reporting: Visualizing Your SEO Data
DMSS: SEO Insights, Analysis & Reporting: Visualizing Your SEO DataSam Partland
 
Mass Conversions | Product Mix | Conversion Optimization
Mass Conversions | Product Mix | Conversion OptimizationMass Conversions | Product Mix | Conversion Optimization
Mass Conversions | Product Mix | Conversion OptimizationRoland Frasier
 
Solutions Workshop – Auctions in the Cloud
Solutions Workshop – Auctions in the CloudSolutions Workshop – Auctions in the Cloud
Solutions Workshop – Auctions in the CloudSAP Ariba
 
How to Energize Your Digital Solar Marketing Strategies
How to Energize Your Digital Solar Marketing StrategiesHow to Energize Your Digital Solar Marketing Strategies
How to Energize Your Digital Solar Marketing StrategiesMaciej Godlewski
 
Essential tools and tips for selling online bridgewater 12.06.15
Essential tools and tips for selling online   bridgewater 12.06.15Essential tools and tips for selling online   bridgewater 12.06.15
Essential tools and tips for selling online bridgewater 12.06.15Get up to Speed
 

Similar to Data Warehouse and OLAP - Lear-Fabini (20)

Data ware housing- Introduction to olap .
Data ware housing- Introduction to  olap .Data ware housing- Introduction to  olap .
Data ware housing- Introduction to olap .
 
4th Autoremarketing Forum India 2017
4th Autoremarketing Forum India 20174th Autoremarketing Forum India 2017
4th Autoremarketing Forum India 2017
 
4th Auto Remarketing Forum India 2017
4th Auto Remarketing Forum India 20174th Auto Remarketing Forum India 2017
4th Auto Remarketing Forum India 2017
 
Building a semantic/metrics layer using Calcite
Building a semantic/metrics layer using CalciteBuilding a semantic/metrics layer using Calcite
Building a semantic/metrics layer using Calcite
 
Running Complex Sourcing Events – A Best Practices Approach
Running Complex Sourcing Events – A Best Practices ApproachRunning Complex Sourcing Events – A Best Practices Approach
Running Complex Sourcing Events – A Best Practices Approach
 
Increase auto dealership sales
Increase auto dealership sales Increase auto dealership sales
Increase auto dealership sales
 
Content Commerce + Growth Strategies For Online Retailers
Content Commerce + Growth Strategies For Online RetailersContent Commerce + Growth Strategies For Online Retailers
Content Commerce + Growth Strategies For Online Retailers
 
Cdm presentation 10-2010
Cdm presentation  10-2010Cdm presentation  10-2010
Cdm presentation 10-2010
 
Writing Ads for Autos Classified Sites That Work
Writing Ads for Autos Classified Sites That WorkWriting Ads for Autos Classified Sites That Work
Writing Ads for Autos Classified Sites That Work
 
2 day ism workshop v1.1
2 day ism workshop v1.12 day ism workshop v1.1
2 day ism workshop v1.1
 
10+ ways to get MORE from Google Analytics
10+ ways to get MORE from Google Analytics10+ ways to get MORE from Google Analytics
10+ ways to get MORE from Google Analytics
 
Business Eye 360 EN
Business Eye 360 ENBusiness Eye 360 EN
Business Eye 360 EN
 
Automotive Syndication
Automotive SyndicationAutomotive Syndication
Automotive Syndication
 
DMSS: SEO Insights, Analysis & Reporting: Visualizing Your SEO Data
DMSS: SEO Insights, Analysis & Reporting: Visualizing Your SEO DataDMSS: SEO Insights, Analysis & Reporting: Visualizing Your SEO Data
DMSS: SEO Insights, Analysis & Reporting: Visualizing Your SEO Data
 
Law of supply
Law of supplyLaw of supply
Law of supply
 
Mass Conversions | Product Mix | Conversion Optimization
Mass Conversions | Product Mix | Conversion OptimizationMass Conversions | Product Mix | Conversion Optimization
Mass Conversions | Product Mix | Conversion Optimization
 
Solutions Workshop – Auctions in the Cloud
Solutions Workshop – Auctions in the CloudSolutions Workshop – Auctions in the Cloud
Solutions Workshop – Auctions in the Cloud
 
How to Energize Your Digital Solar Marketing Strategies
How to Energize Your Digital Solar Marketing StrategiesHow to Energize Your Digital Solar Marketing Strategies
How to Energize Your Digital Solar Marketing Strategies
 
Essential tools and tips for selling online bridgewater 12.06.15
Essential tools and tips for selling online   bridgewater 12.06.15Essential tools and tips for selling online   bridgewater 12.06.15
Essential tools and tips for selling online bridgewater 12.06.15
 
Step_1._Know_The_Game
Step_1._Know_The_GameStep_1._Know_The_Game
Step_1._Know_The_Game
 

Data Warehouse and OLAP - Lear-Fabini

  • 1. DataWarehouses, OLAP, and the CUBE operator Jake Lear, Scott Fabini CS586 -Winter 2015
  • 2. OLTP/OLAP Comparison OLAP: On-Line Analytic Processing OLTP: On-Line Transaction Processing OLTP Query for A Single Sales Order in an SAP DB OLAP Query for revenue by Geography / Product- Line in an IBM Cognos DB
  • 3. OLTP/OLAP Comparison OLTP • Simple, frequent queries • Up-to-the-minute information • Fast response time needed OLAP • Few queries, but very complex • Lots of indexes • May run for hours • Doesn’t need up-to-the-minute info
  • 5. OLAP Queries • We have a long-running transaction analyzing all sales data. • What about the new sales data coming into the database while our transaction is running? • Talk to your neighbor. Think in terms of serializable transactions and locking mechanisms… • Recall, Reads get an S-Lock. Writers forbidden from getting their X-Lock StalledTransactions! Animation
  • 7. The DataWarehouse Congregates Multiple Data Sources CRM SCP ERP DataWarehouse Supply Chain (Vendor) Data Factory Planning Data Sales/ Marketing Data OLAP Queries What is our worst-selling vehicle? Do we need another factory to meet demand? Should we focus sales on Europe or Japan?
  • 8. Summarizing the Motivation for OLAP • We want to add lots of Indexes for faster search, and perform long-running transactions, but this slows down the DB • We only need to look at the long term trends, not up-to-the- second data • We may want to aggregate data from multiple DBs • Answer: Move the data to a DataWarehouse for targeted analysis. Use OLAP techniques which we learn today to slice & dice the massive aggregate into discrete actionable data.
  • 9. Auto Sales Example • Say we want to record in a data warehouse all auto sales • We would create aTable with key info for the sale • Serial Number, Dealer Name, Date of Sale, Price of Sale • The relation becomes our FactTable: • sales(auto, dealer, date, price)
  • 10. Visualizing Multidimensional Data • FactTable: a central relation or collection of data • E.g. all information about a sale of an automobile • Dimensions: Represent the properties of the sale Dealer Days Auto
  • 11. Dealer Auto Dicing the Data • The FactTable is ‘diced’ (divided) by its dimensions - the DimensionTables Date Boring Barney’s WittyWilma’s Friendly Fred’s Gobi Aardvark 200120022003200420052006
  • 12. Price Dependent AttributesDimension attributes AutoDealerDate ColorModelSerial# Phone#CityNameYearMonthDay Dealer Dimension Auto Dimension Days Dimension Price Sales FactTable Implementation: Star Schema Date Dimension allows us to aggregate by year, month, or week Dealer Dimension allows us to aggregate by dealer Auto Dimension allows us to aggregate by Model or Color Animation Dependent Attributes help group Aggregate data, (like sum of prices of autos sold) -
  • 13. Working within a Star Schema • A Star Schema example can be found in my personal ‘sfabini’ CAT database • Connect by issuing the following command: Please do not alter the database
  • 14. ColorModelSerial# Phone#CityName YearMonthDay Dealer Dimension Auto Dimension Days Dimension Price Implementation: Star Schema Dimensions -
  • 15. Price Dependent AttributesDimension attributes Auto DealerDate ColorModelSerial# Phone#CityName YearMonthDay Dealer DimensionAuto Dimension Date Dimension Price Sales FactTable Implementation: Star Schema FactTable -
  • 16. Dealer Auto Dicing the Data • Recapping, does everyone see the ‘dimensions’ and how they divide the FactTable? • Date divided along x axis • Different dealers on y axis • Different autos on z axis • Within the cube (fact table) are the dots -- individual auto sales, including how much it sold for (price) Date Boring Barney’s WittyWilma’s Friendly Fred’s Gobi Aardvark 200120022003200420052006
  • 17. Dealer Auto Exercise: Slicing the Data • Find Average Sales Price by State SELECT state, AVG(price) FROM sales, dealers WHERE sales.dealer = dealer.name GROUP BY state; Date Boring Barney’s WittyWilma’s Arizona New M exico Friendly Fred’s Try it yourself! Which state’s dealers maximize ASP (average selling price)?
  • 18. Dealer Auto Exercise: Drilling Down • FindTotal Sales Price for Gobis at Friendly Fred’s SELECT color, SUM(price) FROM sales, NATURAL JOIN autos JOIN dealer ON name = sales.dealer WHERE sales.dealer = ‘Friendly Fred’ AND Model = ‘Gobi’ GROUP BY color; Date Boring Barney’s WittyWilma’s Arizona New M exico Friendly Fred’s Try it yourself! Joining tables in your query, and then Grouping ‘drills down’ the table
  • 19. Rolling Up and Drilling Down • Drill-Down: Focusing on specific values in certain dimensions • looking at the sales of red Gobis at Friendly Fred’s • Roll-Up: Aggregate along one or more dimensions • Looking at all colors as groups to find the best selling color overall
  • 20. Foundations of the CUBE Operator Dealer Date Auto Sum of price of all autos, by a specific dealer, on all dates Sum of price of a specific auto, by a specific dealer, on all datesPrice of a specific auto, by a specific dealer, on a specific date The Cube operator adds a border of aggregations to the data cube across all combinations of dimensions. Sum of price of all autos, by all dealers, on all dates
  • 21. CUBE vs. ROLLUP Operators • WITH CUBE: If we add the termWITH CUBE to a group-by clause, then we get not only the tuples for the group , but also the tuples that represent aggregation along one or more dimensions along which we have grouped • WITH ROLLUP: A variant of the CUBE operator that produces the additional aggregated tuples over the tail of the sequence of grouping attributes
  • 22. Working with a Cube and phpMyAdmin • We need to use MySQL to demonstrate Cube/Rollup • A Cube example can be found in my personal ‘sfabini’ CAT database • Connect via website: cat.pdx.edu/phpMyAdmin/
  • 23. Working with a Cube • We need to use MySQL to demonstrate Cube/Rollup • A Cube example can be found in my personal ‘sfabini’ CAT database • Connect by issuing the following command:
  • 24. ROLLUP Query in MySQL • SELECT model, color, DATE, dealer, SUM( val ) ,  SUM( cnt )  FROM SalesCube GROUP BY model, color, DATE, dealer WITH ROLLUP
  • 25. Results: Auto SalesWITH ROLLUP in MySQL Aggregate of blue Gobis sold Aggregate of red Gobis sold Aggregate of all Gobis sold Aggregate of all cars sold Aggregate of red Gobis sold by any dealer on this date
  • 26. CUBE Query in SQL99 • SELECT model, color, DATE, dealer, SUM( val ) ,  SUM( cnt )  FROM SalesCube GROUP BY model, color, DATE, dealer WITH CUBE
  • 27. • CUBE Query Result (Partial): • Rollup Query Result: Comparison:WITH ROLLUP vs. WITH CUBE results All colors of Gobis sold at Friendly Fred’s on 5/21 Aggregate of all Gobis sold Aggregate of all autos sold Aggregate of all Gobi sales by any dealer on 5/21 … all such combinations are listedWITH CUBE Red Gobis sold at Friendly Fred’s on 5/21 Red Gobis sold at any dealer on 5/21 Red Gobis sold at any dealer on any date Any Gobi sold at any dealer on any date Aggregate of all autos sold
  • 28. Homework • 1a) Use the ‘sfabini’ mysql db to answer Exercise 10.7.2 (a) and (b) from the book • Notes: • Execute your query FROM the SalesCube table • Use theWITH ROLLUP operator, instead ofWITH CUBE • Smilin Sally is spelled without the apostrophe in the DB • See Example 10.33 for further hints on usingWITH ROLLUP