SlideShare a Scribd company logo
Enabling Applications with
Informix' new OLAP functionality
Ajaykumar Gupte
IBM
1
Agenda
•What is OLAP
•OLAP functions in Informix
– the OVER clause
– supported OLAP functions
•Questions?
What is OLAP?
• On-Line Analytical Processing
• Commonly used in Business
Intelligence (BI) tools
– ranking products, salesmen, items, etc
– exposing trends in sales from historic data
– testing business scenarios (forecast)
– sales breakdown or aggregates on multiple dimensions
(Time, Region, Demographics, etc)
OLAP Functions in Informix
• Supports subset of commonly used
OLAP functions
• Enables more efficient query
processing from BI tools such as
Cognos
Example query with group by
select customer_num, count(*)
from orders
where customer_num <= 110
group by customer_num;
customer_num (count(*))
101 1
104 4
106 2
110 2
4 row(s) retrieved.
Example query with OLAP function
select customer_num, ship_date, ship_charge,
count(*) over (partition by customer_num)
from orders
where customer_num <= 110;
customer_num ship_date ship_charge (count(*))
101 05/26/2008 $15.30 1
104 05/23/2008 $10.80 4
104 07/03/2008 $5.00 4
104 06/01/2008 $10.00 4
104 07/10/2008 $12.20 4
106 05/30/2008 $19.20 2
106 07/03/2008 $12.30 2
110 07/06/2008 $13.80 2
110 07/16/2008 $6.30 2
9 row(s) retrieved.
Where does OLAP function fit?
Joins, group by,
having,
aggregation
OLAP functions
Final order by
OLAP function as predicates
• Use derived table query block to compute
OLAP function first
select * from
(select customer_num, ship_date,
ship_charge,
count(*) over (partition by
customer_num) as cnt
from orders
where customer_num <= 110)
where cnt >= 3;
OLAP function example
• Running 3-month average sales for a
particular product during a particular period
select product_name,
avg(sales) over (
partition by region
order by year, month
rows between 1 preceding and 1 following
)
from total_sales
where product_id = 105
and year between 2001 and 2010;
The over() Clause
olap_func(arg) over(partition by clause
order by clause window frame clause)
• Defines the “domain” of OLAP function
calculation
– partition by: divide into partitions
– order by: ordering within each partition
– window frame: sliding window within each partition
– all clauses optional
Partition By
sum(x) over (
partition by a, b
order by c, d
rows between 2 preceding and 2 following)
a=1, b=1
a=2, b=2
a=1, b=2
a=2, b=1
Order By
sum(x) over (
partition by a, b
order by c, d
rows between 2 preceding and 2 following)
partition a=1, b=2
c=1,d=1
c=1,d=2
c=1,d=3
c=2,d=2
c=2,d=4
c=3,d=1
c=4,d=1
c=4,d=2
Window Frame
c=1,d=1
c=1,d=2
c=1,d=3
c=2,d=2
c=2,d=4
c=3,d=1
c=4,d=1
c=4,d=2
sum(x) over (
partition by a, b
order by c, d
rows between 2 preceding and 2
following)
Partition By
• Divide result set of query into partitions for
computing of an OLAP function
• If partition by clause is not specified, then
entire result set is a single partition
max(salary) over (partition by dept_id)
sum(sales) over (partition by region)
avg(price) over ()
Order By
• Ordering within each partition
• Required for some OLAP functions
–ranking, window frame clause
• Support ASC/DESC, NULLS FIRST/NULLS LAST
rank() over (partition by dept
order by salary desc)
dense_rank() over(order by total_sales
nulls last)
Window Frame
• Defines a sliding window within a partition
• OLAP function value computed from rows in the
sliding window
• Order by clause is required
Physical vs. Logical Window Frame
• Physical window frame
– ROWS keyword
– count offset by position
– fixed window size
– order by one or more column expressions
• Logical window frame
– RANGE keyword
– count offset by value
– window size may vary
– order by single column (numeric, date or datetime type)
Window Frame Examples
avg(price) over (order by year, day
rows between 6 preceding and current row)
count(*) over (order by ship_date
range between 2 preceding and 2
following)
• Current row can be physically outside the window
avg(sales) over (order by month
range between 3 preceding and 1
preceding)
sum(sales) over (order by month
rows between 2 following and 5 following)
Order By – Special Semantics
• “cumulative” semantics in absence of window
frame clause
– for OLAP function that allows window frame clause
– equivalent to “ROWS between unbounded preceding
and current row”
select sales, sum(sales) over (order by quarter)
from sales where year = 2012
sales (sum)
120 120
135 255
127 382
153 535
Supported OLAP Functions
• Ranking functions
– RANK, DENSE_RANK (DENSERANK)
– PERCENT_RANK, CUME_DIST, NTILE
– LEAD, LAG
• Numbering functions
– ROW_NUMBER (ROWNUMBER)
• Aggregate functions
– SUM, COUNT, AVG, MIN, MAX
– STDEV, VARIANCE, RANGE
– FIRST_VALUE, LAST_VALUE
– RATIO_TO_REPORT (RATIOTOREPORT)
Ranking Functions
• Partition by clause is optional
• Order by clause is required
• Window frame clause is NOT allowed
• Duplicate value handling is different between
rank() and dense_rank()
– same rank given to all duplicates
– next rank used “skips” ranks already covered by duplicates
in rank(), but uses next rank for dense_rank()
RANK vs DENSE_RANK
select emp_num, sales,
rank() over (order by sales) as rank,
dense_rank() over (order by sales) as dense_rank
from sales;
emp_num sales rank dense_rank
101 2,000 1 1
102 2,400 2 2
103 2,400 2 2
104 2,500 4 3
105 2,500 4 3
106 2,650 6 4
PERCENT_RANK and CUME_DIST
• Calculates ranking information as a percentile
• Returns value between 0 and 1
select emp_num, sales,
percent_rank() over (order by sales) as per_rank,
cume_dist() over (order by sales) as cume_dist
from sales;
emp_num sales per_rank cume_dist
101 2,000 0 0.166666667
102 2,400 0.2 0.500000000
103 2,400 0.2 0.500000000
104 2,500 0.6 0.833333333
105 2,500 0.6 0.833333333
106 2,650 1.0 1.000000000
NTILE
• Divides the ordered data set into N
number of tiles indicated by the
expression.
• Number of tiles needs to be exact
numeric with scale zero
NTILE Example
select name, salary,
ntile(5) over (partition by dept order by salary)
from employee;
name salary (ntile)
John 35,000 1
Jack 38,400 1
Julie 41,200 2
Manny 45,600 2
Nancy 47,300 3
Pat 49,500 4
Ray 51,300 5
LEAD and LAG
LEAD(expr, offset, default)
LAG(expr, offset, default)

Gives LEAD/LAG value of the expression at the
specified offset

offset is optional, default to 1 if not specified

default is optional, NULL if not specified
• default used when offset goes beyond current partition
boundary

NULL handling
RESPECT NULLS (default)
IGNORE NULLS
LEAD/LAG Example
select name, salary, lag(salary)
over (partition by dept order by salary),
lead(salary, 1, 0)
over (partition by dept order by salary)
from employee;
name salary (lag) (lead)
John 35,000 38,400
Jack 38,400 35,000 41,200
Julie 41,200 38,400 45,600
Manny 45,600 41,200 47,300
Nancy 47,300 45,600 49,500
Pat 49,500 47,300 51,300
Ray 51,300 49,500 0
LEAD/LAG NULL handling
select price,
lag(price ignore nulls, 1) over (order by day),
lead(price, 1) ignore nulls over (order by day)
from stock_price;
price (lag) (lead)
18.25 18.37
18.37 18.25 19.03
18.37 19.03
18.37 19.03
19.03 18.37 18.59
18.59 19.03 18.21
18.21 18.59
Numbering Functions
• Partition by clause and order by clause are
optional
• Window frame clause is NOT allowed
• Provides sequential row number to result set
– regardless of duplicates when order by is specified
ROW_NUMBER Example
select row_number() over (order by sales),
emp_num, sales
from sales;
(row_number) emp_num sales
1 101 2,000
2 102 2,400
3 103 2,400
4 104 2,500
5 105 2,500
6 106 2,650
Aggregate Functions
• Partition by, order by and window frame
clauses are all optional
– window frame clause requires order by clause
• All currently supported aggregate functions
– SUM, COUNT, MIN, MAX, AVG, STDEV, RANGE, VARIANCE
• New aggregate functions
– FIRST_VALUE/LAST_VALUE
– RATIO_TO_REPORT
Aggregate Function Example
select price,
avg(price) over (order by day
rows between 1 preceding and 1 following)
from stock_price;
price (avg)
18.25 18.31
18.37 18.31
18.37
19.03
19.03 18.81
18.59 18.61
18.21 18.40
DISTINCT handling
• DISTINCT is supported, however DISTINCT is mutually
exclusive with order by clause or window frame
clause
select emp_id, manager_id,
count(distinct manager_id)
over (partition by department)
from employee;
emp_id manager_id (count)
101 103 3
102 103 3
103 100 3
104 110 3
105 110 3
FIRST_VALUE and LAST_VALUE
• Gives FIRST/LAST value of current partition
• NULL handling
– RESPECT NULLS (default)
– IGNORE NULLS
FIRST_VALUE/LAST_VALUE Example
select price, price – first_value(price)
over (partition by year order by day)
as diff_price
from stock_price;
price diff_price
18.25 0
18.37 0.12
19.03 0.78
18.59 0.34
18.21 -0.04
RATIO_TO_REPORT
• Computes the ratio of current value to
sum of all values in current partition or
window frame.
select emp_num, sales,
ratio_to_report(sales) over (partition by
year order by sales)
from sales;
RATIO_TO_REPORT Example
select year, sales, ratio_to_report(sales)
over (partition by year)
from sales;
year sales (ratio_to_report)
1998 2400 0.2308
1998 2550 0.2452
1998 2650 0.2548
1998 2800 0.2692
1999 2450 0.2311
1999 2575 0.2429
1999 2725 0.2571
1999 2850 0.2689
Nested OLAP Functions
• OLAP function can be nested inside another
OLAP function
select emp_id, salary, salary – first_value(salary)
over (order by rank() over (order by salary))
as diff_salary
from employee;
select sum(ntile(10) over (order by salary))
over (partition by department)
from employee;
OLAP functions and IWA
• Queries containing OLAP functions can be
accelerated by Informix Warehouse
Accelerator (IWA)
• IWA processes majority of the query block
– scan, join, group by, having, aggregation
• Informix server processes OLAP functions
based on query result from IWA
References
• Links to OLAP function in Informix 12.1
documentation
http://pic.dhe.ibm.com/infocenter/informix/v121/inde
x.jsp?topic=%2Fcom.ibm.sqls.doc
%2Fids_sqs_2583.htm
http://pic.dhe.ibm.com/infocenter/informix/v121/inde
x.jsp?topic=%2Fcom.ibm.acc.doc
%2Fids_acc_queries1.htm
Questions?
gupte@us.ibm.com
41

More Related Content

What's hot

Topic 1.4
Topic 1.4Topic 1.4
Topic 1.4
Sue Whale
 
Topic 5.3
Topic 5.3Topic 5.3
Topic 5.3
Sue Whale
 
Topic 5.2
Topic 5.2Topic 5.2
Topic 5.2
Sue Whale
 
Lp graphical and simplexx892
Lp graphical and simplexx892Lp graphical and simplexx892
Lp graphical and simplexx892
Omid Aminzadeh Gohari
 
1. intro. to or &amp; lp
1. intro. to or &amp; lp1. intro. to or &amp; lp
1. intro. to or &amp; lp
Hakeem-Ur- Rehman
 
Mixed-integer and Disjunctive Programming - Ignacio E. Grossmann
Mixed-integer and Disjunctive Programming - Ignacio E. GrossmannMixed-integer and Disjunctive Programming - Ignacio E. Grossmann
Mixed-integer and Disjunctive Programming - Ignacio E. Grossmann
CAChemE
 

What's hot (6)

Topic 1.4
Topic 1.4Topic 1.4
Topic 1.4
 
Topic 5.3
Topic 5.3Topic 5.3
Topic 5.3
 
Topic 5.2
Topic 5.2Topic 5.2
Topic 5.2
 
Lp graphical and simplexx892
Lp graphical and simplexx892Lp graphical and simplexx892
Lp graphical and simplexx892
 
1. intro. to or &amp; lp
1. intro. to or &amp; lp1. intro. to or &amp; lp
1. intro. to or &amp; lp
 
Mixed-integer and Disjunctive Programming - Ignacio E. Grossmann
Mixed-integer and Disjunctive Programming - Ignacio E. GrossmannMixed-integer and Disjunctive Programming - Ignacio E. Grossmann
Mixed-integer and Disjunctive Programming - Ignacio E. Grossmann
 

Viewers also liked

Conquering Data Monitoring Challenges in the Realm of Derivatives Trading Sys...
Conquering Data Monitoring Challenges in the Realm of Derivatives Trading Sys...Conquering Data Monitoring Challenges in the Realm of Derivatives Trading Sys...
Conquering Data Monitoring Challenges in the Realm of Derivatives Trading Sys...
LiveAction Next Generation Network Management Software
 
"Наш глас" - лист ученика основне школе Нада Пурић Ваљево - март 2014.
"Наш глас" - лист ученика основне школе Нада Пурић Ваљево - март 2014."Наш глас" - лист ученика основне школе Нада Пурић Ваљево - март 2014.
"Наш глас" - лист ученика основне школе Нада Пурић Ваљево - март 2014.
nerconja
 
asdasdasd
asdasdasdasdasdasd
asdasdasd
manjunath .
 
Catfish moon
Catfish moonCatfish moon
Catfish moon
Terry Power
 
Is the Network Tap Mightier Than the Sword
Is the Network Tap Mightier Than the SwordIs the Network Tap Mightier Than the Sword
Is the Network Tap Mightier Than the Sword
LiveAction Next Generation Network Management Software
 
Figaronron - Festival du tuning Mons expo (22-03-2009)
Figaronron - Festival du tuning Mons expo (22-03-2009)Figaronron - Festival du tuning Mons expo (22-03-2009)
Figaronron - Festival du tuning Mons expo (22-03-2009)Figaronron Figaronron
 
Taller Instrumentos
Taller InstrumentosTaller Instrumentos
Taller Instrumentos
Google
 
Les 10 claus del cas mercuri
Les 10 claus del cas mercuriLes 10 claus del cas mercuri
Les 10 claus del cas mercuri
iSabadell
 
Comparative superlative
Comparative superlativeComparative superlative
Comparative superlative
salomon2588
 
Body language
Body languageBody language
Body language
shart sood
 
Svekrva
SvekrvaSvekrva
Svekrvarader1
 
Un sueño presentación
Un sueño presentaciónUn sueño presentación
Un sueño presentación
Esperanza Villafañe Domínguez
 
Figaronron - Disneyland Paris 14 (12-08-2009)
Figaronron - Disneyland Paris 14 (12-08-2009)Figaronron - Disneyland Paris 14 (12-08-2009)
Figaronron - Disneyland Paris 14 (12-08-2009)Figaronron Figaronron
 
ACS CERM Presentation
ACS CERM PresentationACS CERM Presentation
ACS CERM Presentation
Paula Hoffmann
 
Quizy.me
Quizy.meQuizy.me
Quizy.me
omerekinci
 
Zimske i novogodisnje carolije
Zimske i novogodisnje carolijeZimske i novogodisnje carolije
Zimske i novogodisnje carolije
nerconja
 
Komiks Iga
Komiks IgaKomiks Iga
Komiks Iga
Karolina Zioło
 
Giberelini prezentacija
Giberelini prezentacijaGiberelini prezentacija
Giberelini prezentacija
Aladin Vilić
 

Viewers also liked (20)

Conquering Data Monitoring Challenges in the Realm of Derivatives Trading Sys...
Conquering Data Monitoring Challenges in the Realm of Derivatives Trading Sys...Conquering Data Monitoring Challenges in the Realm of Derivatives Trading Sys...
Conquering Data Monitoring Challenges in the Realm of Derivatives Trading Sys...
 
"Наш глас" - лист ученика основне школе Нада Пурић Ваљево - март 2014.
"Наш глас" - лист ученика основне школе Нада Пурић Ваљево - март 2014."Наш глас" - лист ученика основне школе Нада Пурић Ваљево - март 2014.
"Наш глас" - лист ученика основне школе Нада Пурић Ваљево - март 2014.
 
asdasdasd
asdasdasdasdasdasd
asdasdasd
 
Blogs et IE...Google
Blogs et IE...GoogleBlogs et IE...Google
Blogs et IE...Google
 
Catfish moon
Catfish moonCatfish moon
Catfish moon
 
Is the Network Tap Mightier Than the Sword
Is the Network Tap Mightier Than the SwordIs the Network Tap Mightier Than the Sword
Is the Network Tap Mightier Than the Sword
 
Figaronron - Festival du tuning Mons expo (22-03-2009)
Figaronron - Festival du tuning Mons expo (22-03-2009)Figaronron - Festival du tuning Mons expo (22-03-2009)
Figaronron - Festival du tuning Mons expo (22-03-2009)
 
Taller Instrumentos
Taller InstrumentosTaller Instrumentos
Taller Instrumentos
 
Les 10 claus del cas mercuri
Les 10 claus del cas mercuriLes 10 claus del cas mercuri
Les 10 claus del cas mercuri
 
Comparative superlative
Comparative superlativeComparative superlative
Comparative superlative
 
Body language
Body languageBody language
Body language
 
Svekrva
SvekrvaSvekrva
Svekrva
 
Un sueño presentación
Un sueño presentaciónUn sueño presentación
Un sueño presentación
 
Figaronron - Disneyland Paris 14 (12-08-2009)
Figaronron - Disneyland Paris 14 (12-08-2009)Figaronron - Disneyland Paris 14 (12-08-2009)
Figaronron - Disneyland Paris 14 (12-08-2009)
 
pace 2
pace 2pace 2
pace 2
 
ACS CERM Presentation
ACS CERM PresentationACS CERM Presentation
ACS CERM Presentation
 
Quizy.me
Quizy.meQuizy.me
Quizy.me
 
Zimske i novogodisnje carolije
Zimske i novogodisnje carolijeZimske i novogodisnje carolije
Zimske i novogodisnje carolije
 
Komiks Iga
Komiks IgaKomiks Iga
Komiks Iga
 
Giberelini prezentacija
Giberelini prezentacijaGiberelini prezentacija
Giberelini prezentacija
 

Similar to Enabling Applications with Informix' new OLAP functionality

Olap Functions Suport in Informix
Olap Functions Suport in InformixOlap Functions Suport in Informix
Olap Functions Suport in Informix
Bingjie Miao
 
5.Analytical Function.pdf
5.Analytical Function.pdf5.Analytical Function.pdf
5.Analytical Function.pdf
ssuser8b6c85
 
Advanced SQL For Data Scientists
Advanced SQL For Data ScientistsAdvanced SQL For Data Scientists
Advanced SQL For Data Scientists
Databricks
 
Advanced functions in PL SQL
Advanced functions in PL SQLAdvanced functions in PL SQL
Advanced functions in PL SQL
Hosein Zare
 
Simplifying SQL with CTE's and windowing functions
Simplifying SQL with CTE's and windowing functionsSimplifying SQL with CTE's and windowing functions
Simplifying SQL with CTE's and windowing functions
Clayton Groom
 
Analytic & Windowing functions in oracle
Analytic & Windowing functions in oracleAnalytic & Windowing functions in oracle
Analytic & Windowing functions in oracle
Logan Palanisamy
 
Feature Engineering - Getting most out of data for predictive models - TDC 2017
Feature Engineering - Getting most out of data for predictive models - TDC 2017Feature Engineering - Getting most out of data for predictive models - TDC 2017
Feature Engineering - Getting most out of data for predictive models - TDC 2017
Gabriel Moreira
 
SQL Windowing
SQL WindowingSQL Windowing
SQL Windowing
Sandun Perera
 
Query optimizer vivek sharma
Query optimizer vivek sharmaQuery optimizer vivek sharma
Query optimizer vivek sharma
aioughydchapter
 
TechEvent 2019: Uses of Row Pattern Matching; Kim Berg Hansen - Trivadis
TechEvent 2019: Uses of Row Pattern Matching; Kim Berg Hansen - TrivadisTechEvent 2019: Uses of Row Pattern Matching; Kim Berg Hansen - Trivadis
TechEvent 2019: Uses of Row Pattern Matching; Kim Berg Hansen - Trivadis
Trivadis
 
Oracle_Analytical_function.pdf
Oracle_Analytical_function.pdfOracle_Analytical_function.pdf
Oracle_Analytical_function.pdf
KalyankumarVenkat1
 
Exploring Advanced SQL Techniques Using Analytic Functions
Exploring Advanced SQL Techniques Using Analytic FunctionsExploring Advanced SQL Techniques Using Analytic Functions
Exploring Advanced SQL Techniques Using Analytic Functions
Zohar Elkayam
 
Exploring Advanced SQL Techniques Using Analytic Functions
Exploring Advanced SQL Techniques Using Analytic FunctionsExploring Advanced SQL Techniques Using Analytic Functions
Exploring Advanced SQL Techniques Using Analytic Functions
Zohar Elkayam
 
Oracle Advanced SQL and Analytic Functions
Oracle Advanced SQL and Analytic FunctionsOracle Advanced SQL and Analytic Functions
Oracle Advanced SQL and Analytic Functions
Zohar Elkayam
 
R user group meeting 25th jan 2017
R user group meeting 25th jan 2017R user group meeting 25th jan 2017
R user group meeting 25th jan 2017
Garrett Teoh Hor Keong
 
Histograms in 12c era
Histograms in 12c eraHistograms in 12c era
Histograms in 12c era
Mauro Pagano
 
Feature Engineering - Getting most out of data for predictive models
Feature Engineering - Getting most out of data for predictive modelsFeature Engineering - Getting most out of data for predictive models
Feature Engineering - Getting most out of data for predictive models
Gabriel Moreira
 
TDC2017 | São Paulo - Trilha Java EE How we figured out we had a SRE team at ...
TDC2017 | São Paulo - Trilha Java EE How we figured out we had a SRE team at ...TDC2017 | São Paulo - Trilha Java EE How we figured out we had a SRE team at ...
TDC2017 | São Paulo - Trilha Java EE How we figured out we had a SRE team at ...
tdc-globalcode
 
Data structure and algorithm using java
Data structure and algorithm using javaData structure and algorithm using java
Data structure and algorithm using java
Narayan Sau
 
Vertica mpp columnar dbms
Vertica mpp columnar dbmsVertica mpp columnar dbms
Vertica mpp columnar dbms
Zvika Gutkin
 

Similar to Enabling Applications with Informix' new OLAP functionality (20)

Olap Functions Suport in Informix
Olap Functions Suport in InformixOlap Functions Suport in Informix
Olap Functions Suport in Informix
 
5.Analytical Function.pdf
5.Analytical Function.pdf5.Analytical Function.pdf
5.Analytical Function.pdf
 
Advanced SQL For Data Scientists
Advanced SQL For Data ScientistsAdvanced SQL For Data Scientists
Advanced SQL For Data Scientists
 
Advanced functions in PL SQL
Advanced functions in PL SQLAdvanced functions in PL SQL
Advanced functions in PL SQL
 
Simplifying SQL with CTE's and windowing functions
Simplifying SQL with CTE's and windowing functionsSimplifying SQL with CTE's and windowing functions
Simplifying SQL with CTE's and windowing functions
 
Analytic & Windowing functions in oracle
Analytic & Windowing functions in oracleAnalytic & Windowing functions in oracle
Analytic & Windowing functions in oracle
 
Feature Engineering - Getting most out of data for predictive models - TDC 2017
Feature Engineering - Getting most out of data for predictive models - TDC 2017Feature Engineering - Getting most out of data for predictive models - TDC 2017
Feature Engineering - Getting most out of data for predictive models - TDC 2017
 
SQL Windowing
SQL WindowingSQL Windowing
SQL Windowing
 
Query optimizer vivek sharma
Query optimizer vivek sharmaQuery optimizer vivek sharma
Query optimizer vivek sharma
 
TechEvent 2019: Uses of Row Pattern Matching; Kim Berg Hansen - Trivadis
TechEvent 2019: Uses of Row Pattern Matching; Kim Berg Hansen - TrivadisTechEvent 2019: Uses of Row Pattern Matching; Kim Berg Hansen - Trivadis
TechEvent 2019: Uses of Row Pattern Matching; Kim Berg Hansen - Trivadis
 
Oracle_Analytical_function.pdf
Oracle_Analytical_function.pdfOracle_Analytical_function.pdf
Oracle_Analytical_function.pdf
 
Exploring Advanced SQL Techniques Using Analytic Functions
Exploring Advanced SQL Techniques Using Analytic FunctionsExploring Advanced SQL Techniques Using Analytic Functions
Exploring Advanced SQL Techniques Using Analytic Functions
 
Exploring Advanced SQL Techniques Using Analytic Functions
Exploring Advanced SQL Techniques Using Analytic FunctionsExploring Advanced SQL Techniques Using Analytic Functions
Exploring Advanced SQL Techniques Using Analytic Functions
 
Oracle Advanced SQL and Analytic Functions
Oracle Advanced SQL and Analytic FunctionsOracle Advanced SQL and Analytic Functions
Oracle Advanced SQL and Analytic Functions
 
R user group meeting 25th jan 2017
R user group meeting 25th jan 2017R user group meeting 25th jan 2017
R user group meeting 25th jan 2017
 
Histograms in 12c era
Histograms in 12c eraHistograms in 12c era
Histograms in 12c era
 
Feature Engineering - Getting most out of data for predictive models
Feature Engineering - Getting most out of data for predictive modelsFeature Engineering - Getting most out of data for predictive models
Feature Engineering - Getting most out of data for predictive models
 
TDC2017 | São Paulo - Trilha Java EE How we figured out we had a SRE team at ...
TDC2017 | São Paulo - Trilha Java EE How we figured out we had a SRE team at ...TDC2017 | São Paulo - Trilha Java EE How we figured out we had a SRE team at ...
TDC2017 | São Paulo - Trilha Java EE How we figured out we had a SRE team at ...
 
Data structure and algorithm using java
Data structure and algorithm using javaData structure and algorithm using java
Data structure and algorithm using java
 
Vertica mpp columnar dbms
Vertica mpp columnar dbmsVertica mpp columnar dbms
Vertica mpp columnar dbms
 

More from Ajay Gupte

Discover the power of Recursive SQL and query transformation with Informix da...
Discover the power of Recursive SQL and query transformation with Informix da...Discover the power of Recursive SQL and query transformation with Informix da...
Discover the power of Recursive SQL and query transformation with Informix da...
Ajay Gupte
 
Using Lateral derived table in Informix database
Using Lateral derived table in Informix databaseUsing Lateral derived table in Informix database
Using Lateral derived table in Informix database
Ajay Gupte
 
Building a Hierarchical Data Model Using the Latest IBM Informix Features
Building a Hierarchical Data Model Using the Latest IBM Informix FeaturesBuilding a Hierarchical Data Model Using the Latest IBM Informix Features
Building a Hierarchical Data Model Using the Latest IBM Informix Features
Ajay Gupte
 
Using JSON/BSON types in your hybrid application environment
Using JSON/BSON types in your hybrid application environmentUsing JSON/BSON types in your hybrid application environment
Using JSON/BSON types in your hybrid application environment
Ajay Gupte
 
How IBM API Management use Informix and NoSQL
How IBM API Management use Informix and NoSQLHow IBM API Management use Informix and NoSQL
How IBM API Management use Informix and NoSQL
Ajay Gupte
 
NoSQL Analytics: JSON Data Analysis and Acceleration in MongoDB World
NoSQL Analytics: JSON Data Analysis and Acceleration in MongoDB WorldNoSQL Analytics: JSON Data Analysis and Acceleration in MongoDB World
NoSQL Analytics: JSON Data Analysis and Acceleration in MongoDB World
Ajay Gupte
 
IBM Informix Database SQL Set operators and ANSI Hash Join
IBM Informix Database SQL Set operators and ANSI Hash JoinIBM Informix Database SQL Set operators and ANSI Hash Join
IBM Informix Database SQL Set operators and ANSI Hash Join
Ajay Gupte
 

More from Ajay Gupte (7)

Discover the power of Recursive SQL and query transformation with Informix da...
Discover the power of Recursive SQL and query transformation with Informix da...Discover the power of Recursive SQL and query transformation with Informix da...
Discover the power of Recursive SQL and query transformation with Informix da...
 
Using Lateral derived table in Informix database
Using Lateral derived table in Informix databaseUsing Lateral derived table in Informix database
Using Lateral derived table in Informix database
 
Building a Hierarchical Data Model Using the Latest IBM Informix Features
Building a Hierarchical Data Model Using the Latest IBM Informix FeaturesBuilding a Hierarchical Data Model Using the Latest IBM Informix Features
Building a Hierarchical Data Model Using the Latest IBM Informix Features
 
Using JSON/BSON types in your hybrid application environment
Using JSON/BSON types in your hybrid application environmentUsing JSON/BSON types in your hybrid application environment
Using JSON/BSON types in your hybrid application environment
 
How IBM API Management use Informix and NoSQL
How IBM API Management use Informix and NoSQLHow IBM API Management use Informix and NoSQL
How IBM API Management use Informix and NoSQL
 
NoSQL Analytics: JSON Data Analysis and Acceleration in MongoDB World
NoSQL Analytics: JSON Data Analysis and Acceleration in MongoDB WorldNoSQL Analytics: JSON Data Analysis and Acceleration in MongoDB World
NoSQL Analytics: JSON Data Analysis and Acceleration in MongoDB World
 
IBM Informix Database SQL Set operators and ANSI Hash Join
IBM Informix Database SQL Set operators and ANSI Hash JoinIBM Informix Database SQL Set operators and ANSI Hash Join
IBM Informix Database SQL Set operators and ANSI Hash Join
 

Recently uploaded

Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Crescat
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptxLORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
lorraineandreiamcidl
 
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Łukasz Chruściel
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
Neo4j
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke
 
Revolutionizing Visual Effects Mastering AI Face Swaps.pdf
Revolutionizing Visual Effects Mastering AI Face Swaps.pdfRevolutionizing Visual Effects Mastering AI Face Swaps.pdf
Revolutionizing Visual Effects Mastering AI Face Swaps.pdf
Undress Baby
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
Aftab Hussain
 
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdfAutomated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
timtebeek1
 
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, FactsALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
Green Software Development
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
Fermin Galan
 
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket ManagementUtilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate
 
GreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-JurisicGreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-Jurisic
Green Software Development
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
Shane Coughlan
 
Webinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for EmbeddedWebinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for Embedded
ICS
 
Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
Ayan Halder
 
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling ExtensionsUI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
Peter Muessig
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
Adele Miller
 
How to write a program in any programming language
How to write a program in any programming languageHow to write a program in any programming language
How to write a program in any programming language
Rakesh Kumar R
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOMLORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
lorraineandreiamcidl
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
rickgrimesss22
 

Recently uploaded (20)

Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptxLORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
 
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
 
Revolutionizing Visual Effects Mastering AI Face Swaps.pdf
Revolutionizing Visual Effects Mastering AI Face Swaps.pdfRevolutionizing Visual Effects Mastering AI Face Swaps.pdf
Revolutionizing Visual Effects Mastering AI Face Swaps.pdf
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
 
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdfAutomated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
 
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, FactsALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
 
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket ManagementUtilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
 
GreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-JurisicGreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-Jurisic
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
 
Webinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for EmbeddedWebinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for Embedded
 
Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
 
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling ExtensionsUI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
 
How to write a program in any programming language
How to write a program in any programming languageHow to write a program in any programming language
How to write a program in any programming language
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOMLORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
 

Enabling Applications with Informix' new OLAP functionality

  • 1. Enabling Applications with Informix' new OLAP functionality Ajaykumar Gupte IBM 1
  • 2. Agenda •What is OLAP •OLAP functions in Informix – the OVER clause – supported OLAP functions •Questions?
  • 3. What is OLAP? • On-Line Analytical Processing • Commonly used in Business Intelligence (BI) tools – ranking products, salesmen, items, etc – exposing trends in sales from historic data – testing business scenarios (forecast) – sales breakdown or aggregates on multiple dimensions (Time, Region, Demographics, etc)
  • 4. OLAP Functions in Informix • Supports subset of commonly used OLAP functions • Enables more efficient query processing from BI tools such as Cognos
  • 5. Example query with group by select customer_num, count(*) from orders where customer_num <= 110 group by customer_num; customer_num (count(*)) 101 1 104 4 106 2 110 2 4 row(s) retrieved.
  • 6. Example query with OLAP function select customer_num, ship_date, ship_charge, count(*) over (partition by customer_num) from orders where customer_num <= 110; customer_num ship_date ship_charge (count(*)) 101 05/26/2008 $15.30 1 104 05/23/2008 $10.80 4 104 07/03/2008 $5.00 4 104 06/01/2008 $10.00 4 104 07/10/2008 $12.20 4 106 05/30/2008 $19.20 2 106 07/03/2008 $12.30 2 110 07/06/2008 $13.80 2 110 07/16/2008 $6.30 2 9 row(s) retrieved.
  • 7. Where does OLAP function fit? Joins, group by, having, aggregation OLAP functions Final order by
  • 8. OLAP function as predicates • Use derived table query block to compute OLAP function first select * from (select customer_num, ship_date, ship_charge, count(*) over (partition by customer_num) as cnt from orders where customer_num <= 110) where cnt >= 3;
  • 9. OLAP function example • Running 3-month average sales for a particular product during a particular period select product_name, avg(sales) over ( partition by region order by year, month rows between 1 preceding and 1 following ) from total_sales where product_id = 105 and year between 2001 and 2010;
  • 10. The over() Clause olap_func(arg) over(partition by clause order by clause window frame clause) • Defines the “domain” of OLAP function calculation – partition by: divide into partitions – order by: ordering within each partition – window frame: sliding window within each partition – all clauses optional
  • 11. Partition By sum(x) over ( partition by a, b order by c, d rows between 2 preceding and 2 following) a=1, b=1 a=2, b=2 a=1, b=2 a=2, b=1
  • 12. Order By sum(x) over ( partition by a, b order by c, d rows between 2 preceding and 2 following) partition a=1, b=2 c=1,d=1 c=1,d=2 c=1,d=3 c=2,d=2 c=2,d=4 c=3,d=1 c=4,d=1 c=4,d=2
  • 13. Window Frame c=1,d=1 c=1,d=2 c=1,d=3 c=2,d=2 c=2,d=4 c=3,d=1 c=4,d=1 c=4,d=2 sum(x) over ( partition by a, b order by c, d rows between 2 preceding and 2 following)
  • 14. Partition By • Divide result set of query into partitions for computing of an OLAP function • If partition by clause is not specified, then entire result set is a single partition max(salary) over (partition by dept_id) sum(sales) over (partition by region) avg(price) over ()
  • 15. Order By • Ordering within each partition • Required for some OLAP functions –ranking, window frame clause • Support ASC/DESC, NULLS FIRST/NULLS LAST rank() over (partition by dept order by salary desc) dense_rank() over(order by total_sales nulls last)
  • 16. Window Frame • Defines a sliding window within a partition • OLAP function value computed from rows in the sliding window • Order by clause is required
  • 17. Physical vs. Logical Window Frame • Physical window frame – ROWS keyword – count offset by position – fixed window size – order by one or more column expressions • Logical window frame – RANGE keyword – count offset by value – window size may vary – order by single column (numeric, date or datetime type)
  • 18. Window Frame Examples avg(price) over (order by year, day rows between 6 preceding and current row) count(*) over (order by ship_date range between 2 preceding and 2 following) • Current row can be physically outside the window avg(sales) over (order by month range between 3 preceding and 1 preceding) sum(sales) over (order by month rows between 2 following and 5 following)
  • 19. Order By – Special Semantics • “cumulative” semantics in absence of window frame clause – for OLAP function that allows window frame clause – equivalent to “ROWS between unbounded preceding and current row” select sales, sum(sales) over (order by quarter) from sales where year = 2012 sales (sum) 120 120 135 255 127 382 153 535
  • 20. Supported OLAP Functions • Ranking functions – RANK, DENSE_RANK (DENSERANK) – PERCENT_RANK, CUME_DIST, NTILE – LEAD, LAG • Numbering functions – ROW_NUMBER (ROWNUMBER) • Aggregate functions – SUM, COUNT, AVG, MIN, MAX – STDEV, VARIANCE, RANGE – FIRST_VALUE, LAST_VALUE – RATIO_TO_REPORT (RATIOTOREPORT)
  • 21. Ranking Functions • Partition by clause is optional • Order by clause is required • Window frame clause is NOT allowed • Duplicate value handling is different between rank() and dense_rank() – same rank given to all duplicates – next rank used “skips” ranks already covered by duplicates in rank(), but uses next rank for dense_rank()
  • 22. RANK vs DENSE_RANK select emp_num, sales, rank() over (order by sales) as rank, dense_rank() over (order by sales) as dense_rank from sales; emp_num sales rank dense_rank 101 2,000 1 1 102 2,400 2 2 103 2,400 2 2 104 2,500 4 3 105 2,500 4 3 106 2,650 6 4
  • 23. PERCENT_RANK and CUME_DIST • Calculates ranking information as a percentile • Returns value between 0 and 1 select emp_num, sales, percent_rank() over (order by sales) as per_rank, cume_dist() over (order by sales) as cume_dist from sales; emp_num sales per_rank cume_dist 101 2,000 0 0.166666667 102 2,400 0.2 0.500000000 103 2,400 0.2 0.500000000 104 2,500 0.6 0.833333333 105 2,500 0.6 0.833333333 106 2,650 1.0 1.000000000
  • 24. NTILE • Divides the ordered data set into N number of tiles indicated by the expression. • Number of tiles needs to be exact numeric with scale zero
  • 25. NTILE Example select name, salary, ntile(5) over (partition by dept order by salary) from employee; name salary (ntile) John 35,000 1 Jack 38,400 1 Julie 41,200 2 Manny 45,600 2 Nancy 47,300 3 Pat 49,500 4 Ray 51,300 5
  • 26. LEAD and LAG LEAD(expr, offset, default) LAG(expr, offset, default)  Gives LEAD/LAG value of the expression at the specified offset  offset is optional, default to 1 if not specified  default is optional, NULL if not specified • default used when offset goes beyond current partition boundary  NULL handling RESPECT NULLS (default) IGNORE NULLS
  • 27. LEAD/LAG Example select name, salary, lag(salary) over (partition by dept order by salary), lead(salary, 1, 0) over (partition by dept order by salary) from employee; name salary (lag) (lead) John 35,000 38,400 Jack 38,400 35,000 41,200 Julie 41,200 38,400 45,600 Manny 45,600 41,200 47,300 Nancy 47,300 45,600 49,500 Pat 49,500 47,300 51,300 Ray 51,300 49,500 0
  • 28. LEAD/LAG NULL handling select price, lag(price ignore nulls, 1) over (order by day), lead(price, 1) ignore nulls over (order by day) from stock_price; price (lag) (lead) 18.25 18.37 18.37 18.25 19.03 18.37 19.03 18.37 19.03 19.03 18.37 18.59 18.59 19.03 18.21 18.21 18.59
  • 29. Numbering Functions • Partition by clause and order by clause are optional • Window frame clause is NOT allowed • Provides sequential row number to result set – regardless of duplicates when order by is specified
  • 30. ROW_NUMBER Example select row_number() over (order by sales), emp_num, sales from sales; (row_number) emp_num sales 1 101 2,000 2 102 2,400 3 103 2,400 4 104 2,500 5 105 2,500 6 106 2,650
  • 31. Aggregate Functions • Partition by, order by and window frame clauses are all optional – window frame clause requires order by clause • All currently supported aggregate functions – SUM, COUNT, MIN, MAX, AVG, STDEV, RANGE, VARIANCE • New aggregate functions – FIRST_VALUE/LAST_VALUE – RATIO_TO_REPORT
  • 32. Aggregate Function Example select price, avg(price) over (order by day rows between 1 preceding and 1 following) from stock_price; price (avg) 18.25 18.31 18.37 18.31 18.37 19.03 19.03 18.81 18.59 18.61 18.21 18.40
  • 33. DISTINCT handling • DISTINCT is supported, however DISTINCT is mutually exclusive with order by clause or window frame clause select emp_id, manager_id, count(distinct manager_id) over (partition by department) from employee; emp_id manager_id (count) 101 103 3 102 103 3 103 100 3 104 110 3 105 110 3
  • 34. FIRST_VALUE and LAST_VALUE • Gives FIRST/LAST value of current partition • NULL handling – RESPECT NULLS (default) – IGNORE NULLS
  • 35. FIRST_VALUE/LAST_VALUE Example select price, price – first_value(price) over (partition by year order by day) as diff_price from stock_price; price diff_price 18.25 0 18.37 0.12 19.03 0.78 18.59 0.34 18.21 -0.04
  • 36. RATIO_TO_REPORT • Computes the ratio of current value to sum of all values in current partition or window frame. select emp_num, sales, ratio_to_report(sales) over (partition by year order by sales) from sales;
  • 37. RATIO_TO_REPORT Example select year, sales, ratio_to_report(sales) over (partition by year) from sales; year sales (ratio_to_report) 1998 2400 0.2308 1998 2550 0.2452 1998 2650 0.2548 1998 2800 0.2692 1999 2450 0.2311 1999 2575 0.2429 1999 2725 0.2571 1999 2850 0.2689
  • 38. Nested OLAP Functions • OLAP function can be nested inside another OLAP function select emp_id, salary, salary – first_value(salary) over (order by rank() over (order by salary)) as diff_salary from employee; select sum(ntile(10) over (order by salary)) over (partition by department) from employee;
  • 39. OLAP functions and IWA • Queries containing OLAP functions can be accelerated by Informix Warehouse Accelerator (IWA) • IWA processes majority of the query block – scan, join, group by, having, aggregation • Informix server processes OLAP functions based on query result from IWA
  • 40. References • Links to OLAP function in Informix 12.1 documentation http://pic.dhe.ibm.com/infocenter/informix/v121/inde x.jsp?topic=%2Fcom.ibm.sqls.doc %2Fids_sqs_2583.htm http://pic.dhe.ibm.com/infocenter/informix/v121/inde x.jsp?topic=%2Fcom.ibm.acc.doc %2Fids_acc_queries1.htm