OLAP Functions Order-Dependent Aggregates and Windows in SQL: SQL:2003---same as SQL:1999.

Slides:



Advertisements
Similar presentations
5.1Database System Concepts - 6 th Edition Chapter 5: Advanced SQL Advanced Aggregation Features OLAP.
Advertisements

Econometric Details -- the market model Assume that asset returns are jointly multivariate normal and independently and identically distributed through.
QUANTITATIVE DATA ANALYSIS
1-1 Regression Models  Population Deterministic Regression Model Y i =  0 +  1 X i u Y i only depends on the value of X i and no other factor can affect.
the Sample Correlation Coefficient
1 1 Data Warehousing Decision-Support Systems  Data Analysis  OLAP  Extended aggregation features in SQL –Windowing and ranking  Implementation Techniques.
Chapter 18: Data Analysis and Mining
Variability Measures of spread of scores range: highest - lowest standard deviation: average difference from mean variance: average squared difference.
©Silberschatz, Korth and Sudarshan22.1Database System Concepts 4 th Edition 1 SQL:1999 Advanced Querying Decision-Support Systems Data Warehousing Data.
©Silberschatz, Korth and Sudarshan22.1Database System Concepts 4 th Edition 1 Extended Aggregation SQL-92 aggregation quite limited  Many useful aggregates.
Copyright: Silberschatz, Korth and Sudarshan 1 OLAP Functions Order-Dependent Aggregates and Windows in SQL: SQL: same as SQL:1999.
Basic Practice of Statistics - 3rd Edition
Computer Science 101 Web Access to Databases SQL – Extended Form.
Lecture 5 Correlation and Regression
Enhancements to the GROUP BY Clause Fresher Learning Program January, 2012.
Database Programming Sections 5– GROUP BY, HAVING clauses, Rollup & Cube Operations, Grouping Set, Set Operations 11/2/10.
Economics 173 Business Statistics Lecture 2 Fall, 2001 Professor J. Petry
Analysis of Variance: Some Review and Some New Ideas
ADVANCE T-SQL: WINDOW FUNCTIONS Rahman Wehelie 7/16/2013 ITC 226.
Computing & Information Sciences Kansas State University Monday, 26 Nov 2007CIS 560: Database System Concepts Lecture 37 of 42 Monday, 26 November 2007.
Review of Measures of Central Tendency, Dispersion & Association
Oracle Analytic Functions for IR Analysis and Reporting Mingguang Xu and Denise Gardner Office of Institutional Research University of Georgia.
Computing & Information Sciences Kansas State University Wednesday, 12 Nov 2008CIS 560: Database System Concepts Lecture 31 of 42 Wednesday, 12 November.
Summary of introduced statistical terms and concepts mean Variance & standard deviation covariance & correlation Describes/measures average conditions.
SQL-5 (Group By.. Having). Group By  Need: To apply the aggregate functions to subgroups of tuples in a relation, where the subgroups are based on some.
Computing & Information Sciences Kansas State University Wednesday, 29 Nov 2006CIS 560: Database System Concepts Lecture 39 of 42 Wednesday, 29 November.
Chapter 6 Simple Regression Introduction Fundamental questions – Is there a relationship between two random variables and how strong is it? – Can.
Chapter 3: Averages and Variation Section 2: Measures of Dispersion.
Environmental Modeling Basic Testing Methods - Statistics III.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Module B: Advanced SQL.
Data warehousing, data analysis and OLAP Sunita Sarawagi
© Jalal Kawash Database Queries Peeking into Computer Science.
Decision support, data mining & data warehousing.
CHAPTER 2: Basic Summary Statistics
Background Lots of Demos(That’s it.)
©Silberschatz, Korth and Sudarshan5.1Database System Concepts - 6 th Edition Recursive Queries.
A Glance at the Window Functions. Window Functions Introduced in SQL 2005 Enhanced in SQL 2012 So-called because they operate on a defined portion of.
Data Preprocessing: Data Reduction Techniques Compiled By: Umair Yaqub Lecturer Govt. Murray College Sialkot.
Biostatistics Class 3 Probability Distributions 2/15/2000.
Correlation and Linear Regression Chapter 13 McGraw-Hill/Irwin Copyright © 2012 by The McGraw-Hill Companies, Inc. All rights reserved.
Data Analysis Decision Support Systems Data Analysis and OLAP Data Warehousing.
VICTORIA UNIVERSITY OF WELLINGTON Te Whare Wananga o te Upoko o te Ika a Maui SWEN 432 Advanced Database Design and Implementation OLAP Queries and SQL:1999.
Lecturer : Dr. Pavle Mogin
Data Mining: Concepts and Techniques
Database Systems Subqueries, Aggregation
Advanced Teradata SQL GLOBAL Temporary Vs VOLATILE Temporary Vs Derived tables WITH and WITH BY Special Index function Trigger Online Analytical Function.
Chapter 5: Advanced SQL Database System concepts,6th Ed.
Using Window Ranking, Offset, and Aggregate Functions
I WANT TO HOLD YOUR HAND 1ST TOP 100 SINGLE
Database Queries.
T-SQL Window Function Deep Dive part 1
Chapter 18: Data Analysis and Mining
Writing Better Queries with Window Functions
Oracle8i Analytical SQL Features
Analysis of Variance: Some Review and Some New Ideas
Chapter 18: Data Analysis and Mining
Introduction to Window Functions
Statistical Process Control
Introduction to T-sql Window functionS
Reporting Aggregated Data Using the Group Functions
CS240B, Winter 2017 Task 2.1:  Using a syntax based on that of notes and the two references above, express a user-defined aggregate d_count to perform.
CS240B: Assignment1 Winter 2016.
Data Warehousing Decision-Support Systems
CHAPTER 2: Basic Summary Statistics
Reporting Aggregated Data Using the Group Functions
Reporting Aggregated Data Using the Group Functions
分组函数 Schedule: Timing Topic 35 minutes Lecture 40 minutes Practice
Aggregating Data Using Group Functions
Intermediate Query Structure and Development
Presentation transcript:

OLAP Functions Order-Dependent Aggregates and Windows in SQL: SQL:2003---same as SQL:1999

Extended Aggregation: OLAP Functions Rank, row_number and other functions based on explicit order Many new statistical functions: see, e.g., DB2 UDB's High-Function Business Intelligence in e-business---Red Book http://www.redbooks.ibm.com/redbooks/SG246546.html VAR(X): variance, STDDEV(X): its square root COV(X,Y): covariance is the measure of the linear association between two variables. CORR(X,Y): correlation is normalized covariance. +1 max correlation, 0 none, -1 inverse Regression functions: Y = a X + b REGR_SLOPE (X) -> a REGR_INTERCEPT (X) -> b More: Chi-squared testing, sampling

OLAP Functions Windows on aggregates: Physical windows: based on the number of rows in the window Logical windows: based on the value span of the window.

Ranking Ranking is done in conjunction with an order by specification. Suppose we are given a relation student-marks(Name, marks) which stores the marks obtained by each student. The following query gives the rank of each student. Select Name, rank ( ) (order by (marks) desc) as s-rank, dense_rank ( ) (order by (marks) desc) as d-rank from student-marks order by s-rank Name Marks Rank DenseRank Tom 8 1 1 Jeff 7 2 2 Mary 7 2 2 Alex 6 4 3

Partition By Ranking can be done within partition of the data. The following query then gives the rank of students within each section: student-marks(student-id, marks); student- section(student-id, section) select student-id, section, rank( ) over (partition by section order by marks desc) as sec-rank from student-marks, student-section where student-marks.student-id = student-section.student-id order by section, sec-rank dense_rank(): no holes after ties row_number(): provide row numbering given a specific partitioning and ordering of rows.

Ranking (Cont.) For a given constant n, the ranking the function ntile(n) takes the tuples in each partition in the specified order, and divides them into n buckets with equal numbers of tuples. For instance, we sort employees by salary, and use ntile(3) to find which range (bottom third, middle third, or top third) each employee is in, and compute the total salary earned by employees in each range: select threetile, sum(salary) from ( select salary, ntile(3) over (order by (salary) as threetile from employee) as s group by threetile SQL permits the user to specify where they should occur by using nulls first or nulls last, for instance select student-id, rank ( ) over (order by marks desc nulls last) as s-rank from student-marks

Aggregates on Windows An example of window query is that, given sales values for each date, calculates for each date the average of the sales on that day, the previous day, and the next day; such moving average queries are used to smooth out random variations. In contrast to group by, the same tuple can exist in multiple windows. Suppose we are given a relation transaction(account-number, date-time, value), select account-number, date-time, sum(value) over (partition by account-number order by date-time range unbounded preceding) This query returns a new sum for each new tuple—cumulative sum! An actual window can also be specified: e.g. range 10 rows preceding range between 10 rows preceding and 4 following range 30 minutes preceding range interval 30 minutes preceding and current row