SlideShare a Scribd company logo
Analytical Functions
After completing this module, you will be able to:
• Enable and Expedite the processing OLAP queries
• Describe the Derivation of Ordered Analytical Functions
Analytical functions
„ Support common operation in analytical and data mining
environment
„ Includes ANSI SQL-99 compliant window functions as well as
Teradata-specific functions
„ It used in Expression list of SELECT statement
Aggregate function Lists
„ Window aggregate functions
„ AVG
„ COUNT
„ MAX
„ MIN
„ SUM
„ Rank function
„ RANK
„ Distribution function
„ PERCENT_RANK
„ Row number function
„ ROW_NUMBER
„ Teradata-specific functions
„ CSUM
„ MAVG
„ MDIFF
„ MLINREG
„ MSUM
„ QUANTILE
„ RANK
Windows Aggregate Functions
Window Feature
ƒ Provides dynamic subset data definition
ƒ ANSI SQL-99 Compliant
Window Clauses
Entire partition following the current row
UNBOUNDED
FOLLOWING
Entire partition preceding the current row
UNBOUNDED
PRECEDING
starting point for the aggregation group within the
Partition.
ROWS
Grouping of rows based on column specified
PARTITION BY
arguments that define how values are grouped, ordered.
OVER
Description
Syntax Element
Computation types
ROWS BETWEEN UNBOUNDED PRECEDING AND
UNBOUNDED FOLLOWING
Group
„ ROWS UNBOUNDED PRECEDING
„ ROWS BETWEEN UNBOUNDED PRECEDING AND value
PRECEDING
„ ROWS BETWEEN UNBOUNDED PRECEDING AND
CURRENT ROW
„ ROWS BETWEEN UNBOUNDED PRECEDING AND
value FOLLOWING
Cumulative
Syntax options
Computation
Computation types contd..
„ ROWS BETWEEN value PRECEDING AND UNBOUNDED
FOLLOWING
„ ROWS BETWEEN CURRENT ROW AND UNBOUNDED
FOLLOWING
„ ROWS BETWEEN value FOLLOWING AND UNBOUNDED
FOLLOWING
Remaining
„ ROWS value PRECEDING
„ ROWS CURRENT ROW
„ ROWS BETWEEN value PRECEDING AND value PRECEDING
„ ROWS BETWEEN value PRECEDING AND CURRENT ROW
„ ROWS BETWEEN value PRECEDING AND value FOLLOWING
„ ROWS BETWEEN CURRENT ROW AND CURRENT ROW
„ ROWS BETWEEN CURRENT ROW AND value FOLLOWING
„ ROWS BETWEEN value FOLLOWING AND value FOLLOWING
Moving
Syntax options
Computation
Analytical functions
select state, zip_code ,
Balance_Forward,
SUM(Balance_Forward) OVER( PARTITION BY Zip_Code
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED
FOLLOWING)
FROM
AU.accounts;
• SUM
• Result
State Zip_Code Balance_F Grouped Sum(Balance_Forward
CA 90020 5003.8 16950545.29
CA 90020 2582.3 16950545.29
CA 90066 1849.26 14484617.91
CA 90066 8392.2 14484617.91
CA 90066 9948.5 14484617.91
Analytical functions
select state, zip_code ,
Balance_Forward,
SUM(Balance_Forward) OVER( PARTITION BY State order by Zip_Code
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED
FOLLOWING)
FROM
AU.accounts;
• AVG
• Result
State Zip_Code Balance_Forward Moving Avg(Balance_Forward)
CA 90020 18419.5 18420
CA 90020 7571.97 12996
CA 90020 2265.76 9419
CA 90020 2707.29 4182
CA 90020 17572.4 7515
CA 90020 5160.96 8480
Analytical functions
select Account_number, Trans_number ,
Trans_amount,
MIN(Trans_Amount) OVER( PARTITION BY Account_number
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED
FOLLOWING)
FROM
AU.Trans
•MIN
• Result
Account_Number Trans_Number Trans_amount Cumulative Max(Trans_Amount)
20025236 1235 94.42 94.42
20025236 11235 102 94.42
20025237 1236 -94.5 -94.5
20025237 21455 106 -94.5
20025237 22458 252 -94.5
20025238 1237 -94.57 -94.57
20025239 1238 -94.65 -94.65
20025239 12238 103 -94.65
Analytical functions
select Account_number, Trans_number ,
Trans_amount,
MAX(Trans_Amount) OVER( PARTITION BY Account_number
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED
FOLLOWING)
FROM
AU.Trans
• MAX
• Result
Account_Number Trans_Number Trans_amount Cumulative Max(Trans_Amount)
20025236 1235 94.42 102
20025236 11235 102 102
20025237 1236 -94.5 252
20025237 21455 106 252
20025237 22458 252 252
20025238 1237 -94.57 -94.57
20025239 1238 -94.65 103
20025239 12238 103 103
RANK Function
„ Returns the rank (1 … n) of all the rows in the group by the value of
sort_expression_list, with the same sort_expression values receiving the same
rank.
„ It is Teradata Extension to ANSI
„ Window Aggregate need to use for ANSI SQL-99
select
Account_number,
Trans_Amount,
RANK(Trans_Amount)
from
AU.Trans
select Account_number,
Trans_Amount,
RANK() OVER(ORDER BY
TRANS_AMOUNT DESC)
from AU.Trans
•Teradata Extn. •ANSI SQL-99
Account_Number Trans_Amount Rank(Trans_Amount)
20033997 2044 1
20033987 2042 2
20033977 2040 3
20033967 2038 4
20033957 2036 5
PERCENT RANK Function
„ Returns the relative rank of rows for a value_expression.
„ SQL-99 window function.
Select
Account_number,
Trans_Amount,
PERCENT_RANK()
OVER(ORDER BY TRANS_AMOUNT DESC)
from
AU.Trans
Account_Number Trans_Amount Percent Rank(Trans_Amount)
20033997 2044 0.000000
20033987 2042 0.000067
20033977 2040 0.000133
20033967 2038 0.000200
20033957 2036 0.000267
ROW NUMBER Function
„ Returns the sequential row number, where the first row is number one, of the
row within its window partition according to the window ordering of the window.
„ SQL-99 window function.
Account_Number Trans_Amount Row Number()
20033997 2044 1
20033987 2042 2
20033977 2040 3
20033967 2038 4
20033957 2036 5
select Account_number, Trans_Amount,
ROW_NUMBER() OVER(ORDER BY TRANS_AMOUNT DESC)
from AU.Trans
CSUM Function
„ Returns the cumulative (or running) sum of a column expression,
assuming the rows are sorted by sort_expression_list.
„ Teradata-specific function.
select
Account_number,
Trans_Amount,
CSUM(Trans_Amount, Account_number desc)
from
au.Trans
Account_Number Trans_Amount CSum(Trans_Amount,1)
20034000 -764.45 -764.45
20033999 -764.37 -1528.82
20033999 833 -695.82
20033998 -764.3 -1460.12
20033997 -764.22 -2224.34
20033997 2044 -180.34
MAVG Function
„ Returns the moving difference between the current row-column value and
the preceding nth row-column value.
„ Teradata-specific function.
select
Account_number,
Trans_Amount,
MAVG(Trans_Amount, 2, Account_number desc)
from
au.Trans
Account_Number Trans_Amount mount,2,Account_Number DESC)
20034000 -764.45 -764
20033999 -764.37 -764
20033999 833 34
20033998 -764.3 34
20033997 -764.22 -764
20033997 2044 640
MDIFF Function
„ Computes the moving average of a column using the current row and the
preceding width-1 rows.
„ Teradata-specific function.
select
Account_number,
Trans_Amount,
MDIFF(Trans_Amount, 1, Account_number desc)
from
au.Trans
Account_Number Trans_Amount mount,1,Account_Number DESC)
20034000 -764.45 ?
20033999 -764.37 0.08
20033999 833 1597.37
20033998 -764.3 -1597.30
20033997 -764.22 0.08
20033997 2044 2808.22
MSUM Function
„ Computes the moving sum of a column using the current row and the
preceding n-1 rows. This function is very similar to the MAVG function.
„ Teradata-specific function.
select
Account_number,
Trans_Amount,
MSUM(Trans_Amount, 1, Account_number desc)
from
au.Trans
Account_Number Trans_Amount mount,1,Account_Number DESC)
20034000 -764.45 -764.45
20033999 -764.37 -764.37
20033999 833 833.00
20033998 -764.3 -764.30
20033997 -764.22 -764.22
20033997 2044 2044.00
QUANTILE Function
„ Computes the moving sum of a column using the current row and the
preceding n-1 rows. This function is very similar to the MAVG function.
„ Teradata-specific function.
select
Account_number,
Trans_Amount,
QUANTILE(1000, Trans_Amount ASC)
from
au.Trans
Account_Number Trans_AmountQuantile(1000,Trans_Amount ASC)
20033985 -763.3 999
20033984 -763.23 999
20033983 -763.15 999
20033997 -764.22 999
20033975 -762.54 998
20033982 -763.07 998
20033980 -762.92 998

More Related Content

What's hot

Oracle SQL Basics
Oracle SQL BasicsOracle SQL Basics
Oracle SQL Basics
Dhananjay Goel
 
Sql commands
Sql commandsSql commands
Nested Queries-SQL.ppt
Nested Queries-SQL.pptNested Queries-SQL.ppt
Nested Queries-SQL.ppt
JayavarapuKarthikJ1
 
Selection sort
Selection sortSelection sort
Selection sort
Abdelrahman Saleh
 
4. plsql
4. plsql4. plsql
4. plsql
Amrit Kaur
 
MySQL INDEXES
MySQL INDEXESMySQL INDEXES
MySQL INDEXES
HripsimeGhaltaghchya
 
Arreglos
ArreglosArreglos
Arreglos
laura291091
 
Data structures
Data structuresData structures
Data structures
Pranav Gupta
 
SQL window functions for MySQL
SQL window functions for MySQLSQL window functions for MySQL
SQL window functions for MySQL
Dag H. Wanvik
 
Sql subquery
Sql  subquerySql  subquery
Sql subquery
Raveena Thakur
 
Cuadro comparativo algoritmos de busqueda
Cuadro comparativo algoritmos de busquedaCuadro comparativo algoritmos de busqueda
Cuadro comparativo algoritmos de busqueda
Cristopher Morales Ruiz
 
SQL Views
SQL ViewsSQL Views
SQL Views
Aaron Buma
 
Alter table command
Alter table commandAlter table command
Alter table command
ravikhandelwal41
 
Single row functions
Single row functionsSingle row functions
Single row functions
Soumyajit Dutta
 
Stacks IN DATA STRUCTURES
Stacks IN DATA STRUCTURESStacks IN DATA STRUCTURES
Stacks IN DATA STRUCTURES
Sowmya Jyothi
 
Circular queue
Circular queueCircular queue
Pass by value and pass by reference
Pass by value and pass by reference Pass by value and pass by reference
Pass by value and pass by reference
TurnToTech
 
Chapter 11 - Sorting and Searching
Chapter 11 - Sorting and SearchingChapter 11 - Sorting and Searching
Chapter 11 - Sorting and Searching
Eduardo Bergavera
 
Sql join
Sql  joinSql  join
Sql join
Vikas Gupta
 
Difference between all topics in oracle
Difference between all topics in oracleDifference between all topics in oracle
Difference between all topics in oracle
PraveenRaj280263
 

What's hot (20)

Oracle SQL Basics
Oracle SQL BasicsOracle SQL Basics
Oracle SQL Basics
 
Sql commands
Sql commandsSql commands
Sql commands
 
Nested Queries-SQL.ppt
Nested Queries-SQL.pptNested Queries-SQL.ppt
Nested Queries-SQL.ppt
 
Selection sort
Selection sortSelection sort
Selection sort
 
4. plsql
4. plsql4. plsql
4. plsql
 
MySQL INDEXES
MySQL INDEXESMySQL INDEXES
MySQL INDEXES
 
Arreglos
ArreglosArreglos
Arreglos
 
Data structures
Data structuresData structures
Data structures
 
SQL window functions for MySQL
SQL window functions for MySQLSQL window functions for MySQL
SQL window functions for MySQL
 
Sql subquery
Sql  subquerySql  subquery
Sql subquery
 
Cuadro comparativo algoritmos de busqueda
Cuadro comparativo algoritmos de busquedaCuadro comparativo algoritmos de busqueda
Cuadro comparativo algoritmos de busqueda
 
SQL Views
SQL ViewsSQL Views
SQL Views
 
Alter table command
Alter table commandAlter table command
Alter table command
 
Single row functions
Single row functionsSingle row functions
Single row functions
 
Stacks IN DATA STRUCTURES
Stacks IN DATA STRUCTURESStacks IN DATA STRUCTURES
Stacks IN DATA STRUCTURES
 
Circular queue
Circular queueCircular queue
Circular queue
 
Pass by value and pass by reference
Pass by value and pass by reference Pass by value and pass by reference
Pass by value and pass by reference
 
Chapter 11 - Sorting and Searching
Chapter 11 - Sorting and SearchingChapter 11 - Sorting and Searching
Chapter 11 - Sorting and Searching
 
Sql join
Sql  joinSql  join
Sql join
 
Difference between all topics in oracle
Difference between all topics in oracleDifference between all topics in oracle
Difference between all topics in oracle
 

Similar to 5.Analytical Function.pdf

Oracle_Analytical_function.pdf
Oracle_Analytical_function.pdfOracle_Analytical_function.pdf
Oracle_Analytical_function.pdf
KalyankumarVenkat1
 
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
 
Advanced functions in PL SQL
Advanced functions in PL SQLAdvanced functions in PL SQL
Advanced functions in PL SQL
Hosein Zare
 
Enabling Applications with Informix' new OLAP functionality
 Enabling Applications with Informix' new OLAP functionality Enabling Applications with Informix' new OLAP functionality
Enabling Applications with Informix' new OLAP functionality
Ajay Gupte
 
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
 
Olap Functions Suport in Informix
Olap Functions Suport in InformixOlap Functions Suport in Informix
Olap Functions Suport in Informix
Bingjie Miao
 
Les03 Single Row Function
Les03 Single Row FunctionLes03 Single Row Function
Design System Design-ASM and Asynchronous Sequential Circuits
Design System Design-ASM and Asynchronous Sequential CircuitsDesign System Design-ASM and Asynchronous Sequential Circuits
Design System Design-ASM and Asynchronous Sequential Circuits
Indira Priyadarshini
 
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
 
SQL Windowing
SQL WindowingSQL Windowing
SQL Windowing
Sandun Perera
 
SQL Performance Tuning and New Features in Oracle 19c
SQL Performance Tuning and New Features in Oracle 19cSQL Performance Tuning and New Features in Oracle 19c
SQL Performance Tuning and New Features in Oracle 19c
RachelBarker26
 
Sql wksht-3
Sql wksht-3Sql wksht-3
Sql wksht-3
Mukesh Tekwani
 
Introduction to Oracle Functions--(SQL)--Abhishek Sharma
Introduction to Oracle Functions--(SQL)--Abhishek SharmaIntroduction to Oracle Functions--(SQL)--Abhishek Sharma
Introduction to Oracle Functions--(SQL)--Abhishek Sharma
अभिषेक शर्मा
 
Oracle SQL Advanced
Oracle SQL AdvancedOracle SQL Advanced
Oracle SQL Advanced
Dhananjay Goel
 
SQL Macros - Game Changing Feature for SQL Developers?
SQL Macros - Game Changing Feature for SQL Developers?SQL Macros - Game Changing Feature for SQL Developers?
SQL Macros - Game Changing Feature for SQL Developers?
Andrej Pashchenko
 
A few things about the Oracle optimizer - 2013
A few things about the Oracle optimizer - 2013A few things about the Oracle optimizer - 2013
A few things about the Oracle optimizer - 2013
Connor McDonald
 
Intro to tsql unit 10
Intro to tsql   unit 10Intro to tsql   unit 10
Intro to tsql unit 10
Syed Asrarali
 
PL/SQL and radix tree structure
PL/SQL and radix tree structurePL/SQL and radix tree structure
PL/SQL and radix tree structure
Viacheslav Kalyakin
 
COIS 420 - Practice 03
COIS 420 - Practice 03COIS 420 - Practice 03
COIS 420 - Practice 03
Angel G Diaz
 

Similar to 5.Analytical Function.pdf (20)

Oracle_Analytical_function.pdf
Oracle_Analytical_function.pdfOracle_Analytical_function.pdf
Oracle_Analytical_function.pdf
 
Oracle Advanced SQL and Analytic Functions
Oracle Advanced SQL and Analytic FunctionsOracle Advanced SQL and Analytic Functions
Oracle Advanced SQL and Analytic Functions
 
Advanced functions in PL SQL
Advanced functions in PL SQLAdvanced functions in PL SQL
Advanced functions in PL SQL
 
Enabling Applications with Informix' new OLAP functionality
 Enabling Applications with Informix' new OLAP functionality Enabling Applications with Informix' new OLAP functionality
Enabling Applications with Informix' new OLAP functionality
 
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
 
Olap Functions Suport in Informix
Olap Functions Suport in InformixOlap Functions Suport in Informix
Olap Functions Suport in Informix
 
Les03 Single Row Function
Les03 Single Row FunctionLes03 Single Row Function
Les03 Single Row Function
 
Design System Design-ASM and Asynchronous Sequential Circuits
Design System Design-ASM and Asynchronous Sequential CircuitsDesign System Design-ASM and Asynchronous Sequential Circuits
Design System Design-ASM and Asynchronous Sequential Circuits
 
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
 
SQL Windowing
SQL WindowingSQL Windowing
SQL Windowing
 
SQL Performance Tuning and New Features in Oracle 19c
SQL Performance Tuning and New Features in Oracle 19cSQL Performance Tuning and New Features in Oracle 19c
SQL Performance Tuning and New Features in Oracle 19c
 
Sql wksht-3
Sql wksht-3Sql wksht-3
Sql wksht-3
 
Introduction to Oracle Functions--(SQL)--Abhishek Sharma
Introduction to Oracle Functions--(SQL)--Abhishek SharmaIntroduction to Oracle Functions--(SQL)--Abhishek Sharma
Introduction to Oracle Functions--(SQL)--Abhishek Sharma
 
Oracle SQL Advanced
Oracle SQL AdvancedOracle SQL Advanced
Oracle SQL Advanced
 
SQL Macros - Game Changing Feature for SQL Developers?
SQL Macros - Game Changing Feature for SQL Developers?SQL Macros - Game Changing Feature for SQL Developers?
SQL Macros - Game Changing Feature for SQL Developers?
 
A few things about the Oracle optimizer - 2013
A few things about the Oracle optimizer - 2013A few things about the Oracle optimizer - 2013
A few things about the Oracle optimizer - 2013
 
Intro to tsql unit 10
Intro to tsql   unit 10Intro to tsql   unit 10
Intro to tsql unit 10
 
PL/SQL and radix tree structure
PL/SQL and radix tree structurePL/SQL and radix tree structure
PL/SQL and radix tree structure
 
COIS 420 - Practice 03
COIS 420 - Practice 03COIS 420 - Practice 03
COIS 420 - Practice 03
 

More from ssuser8b6c85

5.Agg. Function.pdf
5.Agg. Function.pdf5.Agg. Function.pdf
5.Agg. Function.pdf
ssuser8b6c85
 
2.1 Data types.pdf
2.1 Data types.pdf2.1 Data types.pdf
2.1 Data types.pdf
ssuser8b6c85
 
1.8 Data Protection.pdf
1.8 Data Protection.pdf1.8 Data Protection.pdf
1.8 Data Protection.pdf
ssuser8b6c85
 
1.6 PI Mechanics.pdf
1.6  PI Mechanics.pdf1.6  PI Mechanics.pdf
1.6 PI Mechanics.pdf
ssuser8b6c85
 
1.5 PI Access.pdf
1.5 PI Access.pdf1.5 PI Access.pdf
1.5 PI Access.pdf
ssuser8b6c85
 
1.4 System Arch.pdf
1.4 System Arch.pdf1.4 System Arch.pdf
1.4 System Arch.pdf
ssuser8b6c85
 
Spark basic.pdf
Spark basic.pdfSpark basic.pdf
Spark basic.pdf
ssuser8b6c85
 
1.1 Overview.pdf
1.1 Overview.pdf1.1 Overview.pdf
1.1 Overview.pdf
ssuser8b6c85
 
1.1 Intro to WinDDI.pdf
1.1 Intro to WinDDI.pdf1.1 Intro to WinDDI.pdf
1.1 Intro to WinDDI.pdf
ssuser8b6c85
 
6.3 Mload.pdf
6.3 Mload.pdf6.3 Mload.pdf
6.3 Mload.pdf
ssuser8b6c85
 

More from ssuser8b6c85 (10)

5.Agg. Function.pdf
5.Agg. Function.pdf5.Agg. Function.pdf
5.Agg. Function.pdf
 
2.1 Data types.pdf
2.1 Data types.pdf2.1 Data types.pdf
2.1 Data types.pdf
 
1.8 Data Protection.pdf
1.8 Data Protection.pdf1.8 Data Protection.pdf
1.8 Data Protection.pdf
 
1.6 PI Mechanics.pdf
1.6  PI Mechanics.pdf1.6  PI Mechanics.pdf
1.6 PI Mechanics.pdf
 
1.5 PI Access.pdf
1.5 PI Access.pdf1.5 PI Access.pdf
1.5 PI Access.pdf
 
1.4 System Arch.pdf
1.4 System Arch.pdf1.4 System Arch.pdf
1.4 System Arch.pdf
 
Spark basic.pdf
Spark basic.pdfSpark basic.pdf
Spark basic.pdf
 
1.1 Overview.pdf
1.1 Overview.pdf1.1 Overview.pdf
1.1 Overview.pdf
 
1.1 Intro to WinDDI.pdf
1.1 Intro to WinDDI.pdf1.1 Intro to WinDDI.pdf
1.1 Intro to WinDDI.pdf
 
6.3 Mload.pdf
6.3 Mload.pdf6.3 Mload.pdf
6.3 Mload.pdf
 

Recently uploaded

在线办理(英国UCA毕业证书)创意艺术大学毕业证在读证明一模一样
在线办理(英国UCA毕业证书)创意艺术大学毕业证在读证明一模一样在线办理(英国UCA毕业证书)创意艺术大学毕业证在读证明一模一样
在线办理(英国UCA毕业证书)创意艺术大学毕业证在读证明一模一样
v7oacc3l
 
一比一原版(Chester毕业证书)切斯特大学毕业证如何办理
一比一原版(Chester毕业证书)切斯特大学毕业证如何办理一比一原版(Chester毕业证书)切斯特大学毕业证如何办理
一比一原版(Chester毕业证书)切斯特大学毕业证如何办理
74nqk8xf
 
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
Timothy Spann
 
一比一原版(Coventry毕业证书)考文垂大学毕业证如何办理
一比一原版(Coventry毕业证书)考文垂大学毕业证如何办理一比一原版(Coventry毕业证书)考文垂大学毕业证如何办理
一比一原版(Coventry毕业证书)考文垂大学毕业证如何办理
74nqk8xf
 
Challenges of Nation Building-1.pptx with more important
Challenges of Nation Building-1.pptx with more importantChallenges of Nation Building-1.pptx with more important
Challenges of Nation Building-1.pptx with more important
Sm321
 
06-12-2024-BudapestDataForum-BuildingReal-timePipelineswithFLaNK AIM
06-12-2024-BudapestDataForum-BuildingReal-timePipelineswithFLaNK AIM06-12-2024-BudapestDataForum-BuildingReal-timePipelineswithFLaNK AIM
06-12-2024-BudapestDataForum-BuildingReal-timePipelineswithFLaNK AIM
Timothy Spann
 
STATATHON: Unleashing the Power of Statistics in a 48-Hour Knowledge Extravag...
STATATHON: Unleashing the Power of Statistics in a 48-Hour Knowledge Extravag...STATATHON: Unleashing the Power of Statistics in a 48-Hour Knowledge Extravag...
STATATHON: Unleashing the Power of Statistics in a 48-Hour Knowledge Extravag...
sameer shah
 
一比一原版(UO毕业证)渥太华大学毕业证如何办理
一比一原版(UO毕业证)渥太华大学毕业证如何办理一比一原版(UO毕业证)渥太华大学毕业证如何办理
一比一原版(UO毕业证)渥太华大学毕业证如何办理
aqzctr7x
 
Intelligence supported media monitoring in veterinary medicine
Intelligence supported media monitoring in veterinary medicineIntelligence supported media monitoring in veterinary medicine
Intelligence supported media monitoring in veterinary medicine
AndrzejJarynowski
 
一比一原版(Glasgow毕业证书)格拉斯哥大学毕业证如何办理
一比一原版(Glasgow毕业证书)格拉斯哥大学毕业证如何办理一比一原版(Glasgow毕业证书)格拉斯哥大学毕业证如何办理
一比一原版(Glasgow毕业证书)格拉斯哥大学毕业证如何办理
g4dpvqap0
 
办(uts毕业证书)悉尼科技大学毕业证学历证书原版一模一样
办(uts毕业证书)悉尼科技大学毕业证学历证书原版一模一样办(uts毕业证书)悉尼科技大学毕业证学历证书原版一模一样
办(uts毕业证书)悉尼科技大学毕业证学历证书原版一模一样
apvysm8
 
一比一原版(牛布毕业证书)牛津布鲁克斯大学毕业证如何办理
一比一原版(牛布毕业证书)牛津布鲁克斯大学毕业证如何办理一比一原版(牛布毕业证书)牛津布鲁克斯大学毕业证如何办理
一比一原版(牛布毕业证书)牛津布鲁克斯大学毕业证如何办理
74nqk8xf
 
Palo Alto Cortex XDR presentation .......
Palo Alto Cortex XDR presentation .......Palo Alto Cortex XDR presentation .......
Palo Alto Cortex XDR presentation .......
Sachin Paul
 
Population Growth in Bataan: The effects of population growth around rural pl...
Population Growth in Bataan: The effects of population growth around rural pl...Population Growth in Bataan: The effects of population growth around rural pl...
Population Growth in Bataan: The effects of population growth around rural pl...
Bill641377
 
Everything you wanted to know about LIHTC
Everything you wanted to know about LIHTCEverything you wanted to know about LIHTC
Everything you wanted to know about LIHTC
Roger Valdez
 
一比一原版(UMN文凭证书)明尼苏达大学毕业证如何办理
一比一原版(UMN文凭证书)明尼苏达大学毕业证如何办理一比一原版(UMN文凭证书)明尼苏达大学毕业证如何办理
一比一原版(UMN文凭证书)明尼苏达大学毕业证如何办理
nyfuhyz
 
ViewShift: Hassle-free Dynamic Policy Enforcement for Every Data Lake
ViewShift: Hassle-free Dynamic Policy Enforcement for Every Data LakeViewShift: Hassle-free Dynamic Policy Enforcement for Every Data Lake
ViewShift: Hassle-free Dynamic Policy Enforcement for Every Data Lake
Walaa Eldin Moustafa
 
Predictably Improve Your B2B Tech Company's Performance by Leveraging Data
Predictably Improve Your B2B Tech Company's Performance by Leveraging DataPredictably Improve Your B2B Tech Company's Performance by Leveraging Data
Predictably Improve Your B2B Tech Company's Performance by Leveraging Data
Kiwi Creative
 
My burning issue is homelessness K.C.M.O.
My burning issue is homelessness K.C.M.O.My burning issue is homelessness K.C.M.O.
My burning issue is homelessness K.C.M.O.
rwarrenll
 
一比一原版(UCSB文凭证书)圣芭芭拉分校毕业证如何办理
一比一原版(UCSB文凭证书)圣芭芭拉分校毕业证如何办理一比一原版(UCSB文凭证书)圣芭芭拉分校毕业证如何办理
一比一原版(UCSB文凭证书)圣芭芭拉分校毕业证如何办理
nuttdpt
 

Recently uploaded (20)

在线办理(英国UCA毕业证书)创意艺术大学毕业证在读证明一模一样
在线办理(英国UCA毕业证书)创意艺术大学毕业证在读证明一模一样在线办理(英国UCA毕业证书)创意艺术大学毕业证在读证明一模一样
在线办理(英国UCA毕业证书)创意艺术大学毕业证在读证明一模一样
 
一比一原版(Chester毕业证书)切斯特大学毕业证如何办理
一比一原版(Chester毕业证书)切斯特大学毕业证如何办理一比一原版(Chester毕业证书)切斯特大学毕业证如何办理
一比一原版(Chester毕业证书)切斯特大学毕业证如何办理
 
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
 
一比一原版(Coventry毕业证书)考文垂大学毕业证如何办理
一比一原版(Coventry毕业证书)考文垂大学毕业证如何办理一比一原版(Coventry毕业证书)考文垂大学毕业证如何办理
一比一原版(Coventry毕业证书)考文垂大学毕业证如何办理
 
Challenges of Nation Building-1.pptx with more important
Challenges of Nation Building-1.pptx with more importantChallenges of Nation Building-1.pptx with more important
Challenges of Nation Building-1.pptx with more important
 
06-12-2024-BudapestDataForum-BuildingReal-timePipelineswithFLaNK AIM
06-12-2024-BudapestDataForum-BuildingReal-timePipelineswithFLaNK AIM06-12-2024-BudapestDataForum-BuildingReal-timePipelineswithFLaNK AIM
06-12-2024-BudapestDataForum-BuildingReal-timePipelineswithFLaNK AIM
 
STATATHON: Unleashing the Power of Statistics in a 48-Hour Knowledge Extravag...
STATATHON: Unleashing the Power of Statistics in a 48-Hour Knowledge Extravag...STATATHON: Unleashing the Power of Statistics in a 48-Hour Knowledge Extravag...
STATATHON: Unleashing the Power of Statistics in a 48-Hour Knowledge Extravag...
 
一比一原版(UO毕业证)渥太华大学毕业证如何办理
一比一原版(UO毕业证)渥太华大学毕业证如何办理一比一原版(UO毕业证)渥太华大学毕业证如何办理
一比一原版(UO毕业证)渥太华大学毕业证如何办理
 
Intelligence supported media monitoring in veterinary medicine
Intelligence supported media monitoring in veterinary medicineIntelligence supported media monitoring in veterinary medicine
Intelligence supported media monitoring in veterinary medicine
 
一比一原版(Glasgow毕业证书)格拉斯哥大学毕业证如何办理
一比一原版(Glasgow毕业证书)格拉斯哥大学毕业证如何办理一比一原版(Glasgow毕业证书)格拉斯哥大学毕业证如何办理
一比一原版(Glasgow毕业证书)格拉斯哥大学毕业证如何办理
 
办(uts毕业证书)悉尼科技大学毕业证学历证书原版一模一样
办(uts毕业证书)悉尼科技大学毕业证学历证书原版一模一样办(uts毕业证书)悉尼科技大学毕业证学历证书原版一模一样
办(uts毕业证书)悉尼科技大学毕业证学历证书原版一模一样
 
一比一原版(牛布毕业证书)牛津布鲁克斯大学毕业证如何办理
一比一原版(牛布毕业证书)牛津布鲁克斯大学毕业证如何办理一比一原版(牛布毕业证书)牛津布鲁克斯大学毕业证如何办理
一比一原版(牛布毕业证书)牛津布鲁克斯大学毕业证如何办理
 
Palo Alto Cortex XDR presentation .......
Palo Alto Cortex XDR presentation .......Palo Alto Cortex XDR presentation .......
Palo Alto Cortex XDR presentation .......
 
Population Growth in Bataan: The effects of population growth around rural pl...
Population Growth in Bataan: The effects of population growth around rural pl...Population Growth in Bataan: The effects of population growth around rural pl...
Population Growth in Bataan: The effects of population growth around rural pl...
 
Everything you wanted to know about LIHTC
Everything you wanted to know about LIHTCEverything you wanted to know about LIHTC
Everything you wanted to know about LIHTC
 
一比一原版(UMN文凭证书)明尼苏达大学毕业证如何办理
一比一原版(UMN文凭证书)明尼苏达大学毕业证如何办理一比一原版(UMN文凭证书)明尼苏达大学毕业证如何办理
一比一原版(UMN文凭证书)明尼苏达大学毕业证如何办理
 
ViewShift: Hassle-free Dynamic Policy Enforcement for Every Data Lake
ViewShift: Hassle-free Dynamic Policy Enforcement for Every Data LakeViewShift: Hassle-free Dynamic Policy Enforcement for Every Data Lake
ViewShift: Hassle-free Dynamic Policy Enforcement for Every Data Lake
 
Predictably Improve Your B2B Tech Company's Performance by Leveraging Data
Predictably Improve Your B2B Tech Company's Performance by Leveraging DataPredictably Improve Your B2B Tech Company's Performance by Leveraging Data
Predictably Improve Your B2B Tech Company's Performance by Leveraging Data
 
My burning issue is homelessness K.C.M.O.
My burning issue is homelessness K.C.M.O.My burning issue is homelessness K.C.M.O.
My burning issue is homelessness K.C.M.O.
 
一比一原版(UCSB文凭证书)圣芭芭拉分校毕业证如何办理
一比一原版(UCSB文凭证书)圣芭芭拉分校毕业证如何办理一比一原版(UCSB文凭证书)圣芭芭拉分校毕业证如何办理
一比一原版(UCSB文凭证书)圣芭芭拉分校毕业证如何办理
 

5.Analytical Function.pdf

  • 1. Analytical Functions After completing this module, you will be able to: • Enable and Expedite the processing OLAP queries • Describe the Derivation of Ordered Analytical Functions
  • 2. Analytical functions „ Support common operation in analytical and data mining environment „ Includes ANSI SQL-99 compliant window functions as well as Teradata-specific functions „ It used in Expression list of SELECT statement
  • 3. Aggregate function Lists „ Window aggregate functions „ AVG „ COUNT „ MAX „ MIN „ SUM „ Rank function „ RANK „ Distribution function „ PERCENT_RANK „ Row number function „ ROW_NUMBER „ Teradata-specific functions „ CSUM „ MAVG „ MDIFF „ MLINREG „ MSUM „ QUANTILE „ RANK
  • 4. Windows Aggregate Functions Window Feature ƒ Provides dynamic subset data definition ƒ ANSI SQL-99 Compliant Window Clauses Entire partition following the current row UNBOUNDED FOLLOWING Entire partition preceding the current row UNBOUNDED PRECEDING starting point for the aggregation group within the Partition. ROWS Grouping of rows based on column specified PARTITION BY arguments that define how values are grouped, ordered. OVER Description Syntax Element
  • 5. Computation types ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING Group „ ROWS UNBOUNDED PRECEDING „ ROWS BETWEEN UNBOUNDED PRECEDING AND value PRECEDING „ ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW „ ROWS BETWEEN UNBOUNDED PRECEDING AND value FOLLOWING Cumulative Syntax options Computation
  • 6. Computation types contd.. „ ROWS BETWEEN value PRECEDING AND UNBOUNDED FOLLOWING „ ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING „ ROWS BETWEEN value FOLLOWING AND UNBOUNDED FOLLOWING Remaining „ ROWS value PRECEDING „ ROWS CURRENT ROW „ ROWS BETWEEN value PRECEDING AND value PRECEDING „ ROWS BETWEEN value PRECEDING AND CURRENT ROW „ ROWS BETWEEN value PRECEDING AND value FOLLOWING „ ROWS BETWEEN CURRENT ROW AND CURRENT ROW „ ROWS BETWEEN CURRENT ROW AND value FOLLOWING „ ROWS BETWEEN value FOLLOWING AND value FOLLOWING Moving Syntax options Computation
  • 7. Analytical functions select state, zip_code , Balance_Forward, SUM(Balance_Forward) OVER( PARTITION BY Zip_Code ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) FROM AU.accounts; • SUM • Result State Zip_Code Balance_F Grouped Sum(Balance_Forward CA 90020 5003.8 16950545.29 CA 90020 2582.3 16950545.29 CA 90066 1849.26 14484617.91 CA 90066 8392.2 14484617.91 CA 90066 9948.5 14484617.91
  • 8. Analytical functions select state, zip_code , Balance_Forward, SUM(Balance_Forward) OVER( PARTITION BY State order by Zip_Code ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) FROM AU.accounts; • AVG • Result State Zip_Code Balance_Forward Moving Avg(Balance_Forward) CA 90020 18419.5 18420 CA 90020 7571.97 12996 CA 90020 2265.76 9419 CA 90020 2707.29 4182 CA 90020 17572.4 7515 CA 90020 5160.96 8480
  • 9. Analytical functions select Account_number, Trans_number , Trans_amount, MIN(Trans_Amount) OVER( PARTITION BY Account_number ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) FROM AU.Trans •MIN • Result Account_Number Trans_Number Trans_amount Cumulative Max(Trans_Amount) 20025236 1235 94.42 94.42 20025236 11235 102 94.42 20025237 1236 -94.5 -94.5 20025237 21455 106 -94.5 20025237 22458 252 -94.5 20025238 1237 -94.57 -94.57 20025239 1238 -94.65 -94.65 20025239 12238 103 -94.65
  • 10. Analytical functions select Account_number, Trans_number , Trans_amount, MAX(Trans_Amount) OVER( PARTITION BY Account_number ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) FROM AU.Trans • MAX • Result Account_Number Trans_Number Trans_amount Cumulative Max(Trans_Amount) 20025236 1235 94.42 102 20025236 11235 102 102 20025237 1236 -94.5 252 20025237 21455 106 252 20025237 22458 252 252 20025238 1237 -94.57 -94.57 20025239 1238 -94.65 103 20025239 12238 103 103
  • 11. RANK Function „ Returns the rank (1 … n) of all the rows in the group by the value of sort_expression_list, with the same sort_expression values receiving the same rank. „ It is Teradata Extension to ANSI „ Window Aggregate need to use for ANSI SQL-99 select Account_number, Trans_Amount, RANK(Trans_Amount) from AU.Trans select Account_number, Trans_Amount, RANK() OVER(ORDER BY TRANS_AMOUNT DESC) from AU.Trans •Teradata Extn. •ANSI SQL-99 Account_Number Trans_Amount Rank(Trans_Amount) 20033997 2044 1 20033987 2042 2 20033977 2040 3 20033967 2038 4 20033957 2036 5
  • 12. PERCENT RANK Function „ Returns the relative rank of rows for a value_expression. „ SQL-99 window function. Select Account_number, Trans_Amount, PERCENT_RANK() OVER(ORDER BY TRANS_AMOUNT DESC) from AU.Trans Account_Number Trans_Amount Percent Rank(Trans_Amount) 20033997 2044 0.000000 20033987 2042 0.000067 20033977 2040 0.000133 20033967 2038 0.000200 20033957 2036 0.000267
  • 13. ROW NUMBER Function „ Returns the sequential row number, where the first row is number one, of the row within its window partition according to the window ordering of the window. „ SQL-99 window function. Account_Number Trans_Amount Row Number() 20033997 2044 1 20033987 2042 2 20033977 2040 3 20033967 2038 4 20033957 2036 5 select Account_number, Trans_Amount, ROW_NUMBER() OVER(ORDER BY TRANS_AMOUNT DESC) from AU.Trans
  • 14. CSUM Function „ Returns the cumulative (or running) sum of a column expression, assuming the rows are sorted by sort_expression_list. „ Teradata-specific function. select Account_number, Trans_Amount, CSUM(Trans_Amount, Account_number desc) from au.Trans Account_Number Trans_Amount CSum(Trans_Amount,1) 20034000 -764.45 -764.45 20033999 -764.37 -1528.82 20033999 833 -695.82 20033998 -764.3 -1460.12 20033997 -764.22 -2224.34 20033997 2044 -180.34
  • 15. MAVG Function „ Returns the moving difference between the current row-column value and the preceding nth row-column value. „ Teradata-specific function. select Account_number, Trans_Amount, MAVG(Trans_Amount, 2, Account_number desc) from au.Trans Account_Number Trans_Amount mount,2,Account_Number DESC) 20034000 -764.45 -764 20033999 -764.37 -764 20033999 833 34 20033998 -764.3 34 20033997 -764.22 -764 20033997 2044 640
  • 16. MDIFF Function „ Computes the moving average of a column using the current row and the preceding width-1 rows. „ Teradata-specific function. select Account_number, Trans_Amount, MDIFF(Trans_Amount, 1, Account_number desc) from au.Trans Account_Number Trans_Amount mount,1,Account_Number DESC) 20034000 -764.45 ? 20033999 -764.37 0.08 20033999 833 1597.37 20033998 -764.3 -1597.30 20033997 -764.22 0.08 20033997 2044 2808.22
  • 17. MSUM Function „ Computes the moving sum of a column using the current row and the preceding n-1 rows. This function is very similar to the MAVG function. „ Teradata-specific function. select Account_number, Trans_Amount, MSUM(Trans_Amount, 1, Account_number desc) from au.Trans Account_Number Trans_Amount mount,1,Account_Number DESC) 20034000 -764.45 -764.45 20033999 -764.37 -764.37 20033999 833 833.00 20033998 -764.3 -764.30 20033997 -764.22 -764.22 20033997 2044 2044.00
  • 18. QUANTILE Function „ Computes the moving sum of a column using the current row and the preceding n-1 rows. This function is very similar to the MAVG function. „ Teradata-specific function. select Account_number, Trans_Amount, QUANTILE(1000, Trans_Amount ASC) from au.Trans Account_Number Trans_AmountQuantile(1000,Trans_Amount ASC) 20033985 -763.3 999 20033984 -763.23 999 20033983 -763.15 999 20033997 -764.22 999 20033975 -762.54 998 20033982 -763.07 998 20033980 -762.92 998