SlideShare a Scribd company logo
1 of 29
Analytical Functions
For DWH
Emrah METE
i2i-Systems
Expert Analyst&Developer
TROUG – BI/DW SIG Day 2014
03.04.2014
İTÜ
http://emrahmete.wordpress.com/about/
Marmara Üniversitesi - Bilgisayar Teknolojisi ve
Programlama
Yıldız Teknik Üniversitesi - Bilgisayar Mühendisliği
i2i-Systems – Analyst&Developer
emrahmete.wordpress.com
TROUG - Yönetim Kurulu Üyeliği
Emrah METE
Yahoo OracleTurk Grubu Moderatör
Oracle Certified Expert
Agenda
• Analytical Functions..Why?
• Aggregate and Analytic
• First/Last Value
• LAG/LEAD
• Pivoting Operations
• Ranking
• Oracle Pattern Matching
• Questions and Answers
Analytical Functions.. Why?
Aggregate and Analytic
Aggregation (Step 1 - Traditional)
SQL> select department_id,
sum(salary)
from employees
group by department_id;
Aggregation (Step 2 - Analytic)
SQL> select first_name, salary,
sum(salary) over
(order by first_name) as empsal
from employees;
Aggregation (Step 2 - Analytic)
SQL> select first_name, department_id,
sum(salary) over
(partition by department_id order by salary) as deptsal
from employees
order by department_id;
Aggregation (Step 3 - Windowing)
SQL> select employee_id, first_name, salary,
sum(salary) over ( order by employee_id rows
between unbounded preceding and current row) as
cumul
from employees
order by employee_id;
Aggregation (Step 3 - Windowing)
SQL> select employee_id, first_name, salary,
sum(salary) over ( order by employee_id rows
between 1preceding and 1 following) as cumul
from employees
order by employee_id;
Aggregation (Step 3 - Windowing)
First_Value
SQL> select first_name, department_id,
first_value(salary) over
(partition by department_id order by employee_id) as
deptsal
from employees
order by department_id;
Last_Value
SQL> select first_name, department_id, salary,
last_value(salary) over
(partition by department_id order by department_id) as
deptsal
from employees
order by department_id;
LAG & LEAD
SQL> select employee_id, first_name, salary,
LAG (salary, 1) OVER (ORDER BY salary )
AS LAG1
FROM employees;
LAG & LEAD
SQL> select employee_id, first_name, salary,
LEAD (salary, 1) OVER (ORDER BY salary ) AS
LAG1
FROM employees;
LISTAGG
SQL> select department_id, listagg(first_name,’,
’) within group (order by department_id)
as newList
FROM employees
group by department_id;
PIVOT & UNPIVOT
PIVOT & UNPIVOT
Ranking – (Rank)
SQL> SELECT department_id, last_name, salary,
RANK() OVER (PARTITION BY department_id
ORDER BY salary DESC) "Rank"
FROM employees
WHERE department_id = 60
ORDER BY department_id, "Rank", salary;
Ranking – (Dense Rank)
SQL> SELECT department_id, last_name, salary,
RANK () OVER (PARTITION BY department_id
ORDER BY salary DESC) "Rank",
DENSE_RANK () OVER (PARTITION BY
department_id ORDER BY salary DESC) "Drank"
FROM employees
WHERE department_id = 60 ORDER BY "Rank";
Ranking – (Percent Rank)
SQL> SELECT department_id, last_name, salary,
PERCENT_RANK () OVER (PARTITION BY
department_id ORDER BY salary) AS pr
FROM employees
WHERE department_id = 60
ORDER BY department_id, pr;
(rank of row in its partition - 1) / (number of rows in the partition - 1)
Example:
Last_Name: Ernst
(4 - 1) / (5 - 1) = 0,75
- Financial applications seeking
patterns of pricing, trading
volume, and other behavior
- Security applications where
unusual behavior must be
detected.
- Fraud Detection
- Sensor Data analysis.(CEP
App.)
Pattern Matching
Pattern Matching
Pattern:
Start
Bottom
End
Pattern Matching
Pattern Matching
Pattern:
Start End
References
http://connormcdonald.wordpress.com/
http://allthingsoracle.com/experts/alex-nuijten/
Dan Stober [ORACLE ANALYTIC FUNCTIONS WINDOWING CLAUSE]
http://docs.oracle.com/cd/E16655_01/server.121/e17749/toc.htm
http://www.oracle.com/technetwork/database/bi-datawarehousing/sql-analytics-index-
1984365.html
http://docs.oracle.com/cd/B19306_01/server.102/b14200/functions056.htm
http://docs.oracle.com/cd/E16655_01/server.121/e17749/analysis.htm#DWHSG0202
http://docs.oracle.com/cd/B19306_01/server.102/b14200/functions101.htm
http://www.oracle.com/technetwork/database/bi-datawarehousing/sql-analytics-index-
1984365.html
Questions/Answers

More Related Content

What's hot

Michael Bayer Introduction to SQLAlchemy @ Postgres Open
Michael Bayer Introduction to SQLAlchemy @ Postgres OpenMichael Bayer Introduction to SQLAlchemy @ Postgres Open
Michael Bayer Introduction to SQLAlchemy @ Postgres Open
PostgresOpen
 

What's hot (20)

Les01
Les01Les01
Les01
 
07 Using Oracle-Supported Package in Application Development
07 Using Oracle-Supported Package in Application Development07 Using Oracle-Supported Package in Application Development
07 Using Oracle-Supported Package in Application Development
 
Android de la A a la Z XML Ulises Gonzalez
Android de la A a la Z  XML Ulises GonzalezAndroid de la A a la Z  XML Ulises Gonzalez
Android de la A a la Z XML Ulises Gonzalez
 
Lesson01 学会使用基本的SQL语句
Lesson01 学会使用基本的SQL语句Lesson01 学会使用基本的SQL语句
Lesson01 学会使用基本的SQL语句
 
06 Using More Package Concepts
06 Using More Package Concepts06 Using More Package Concepts
06 Using More Package Concepts
 
Michael Bayer Introduction to SQLAlchemy @ Postgres Open
Michael Bayer Introduction to SQLAlchemy @ Postgres OpenMichael Bayer Introduction to SQLAlchemy @ Postgres Open
Michael Bayer Introduction to SQLAlchemy @ Postgres Open
 
1 - Introduction to PL/SQL
1 - Introduction to PL/SQL1 - Introduction to PL/SQL
1 - Introduction to PL/SQL
 
05 Creating Stored Procedures
05 Creating Stored Procedures05 Creating Stored Procedures
05 Creating Stored Procedures
 
PL/SQL CURSORES
PL/SQL CURSORESPL/SQL CURSORES
PL/SQL CURSORES
 
plsql les06
 plsql les06 plsql les06
plsql les06
 
ORACLE PL SQL
ORACLE PL SQLORACLE PL SQL
ORACLE PL SQL
 
09 Managing Dependencies
09 Managing Dependencies09 Managing Dependencies
09 Managing Dependencies
 
Satyapriya rajguru: Every day, in one way or another.
Satyapriya  rajguru:  Every day, in one way or another.Satyapriya  rajguru:  Every day, in one way or another.
Satyapriya rajguru: Every day, in one way or another.
 
High Performance Plsql
High Performance PlsqlHigh Performance Plsql
High Performance Plsql
 
3 sql overview
3 sql overview3 sql overview
3 sql overview
 
Stored procedures
Stored proceduresStored procedures
Stored procedures
 
Database Objects
Database ObjectsDatabase Objects
Database Objects
 
New Stuff in the Oracle PL/SQL Language
New Stuff in the Oracle PL/SQL LanguageNew Stuff in the Oracle PL/SQL Language
New Stuff in the Oracle PL/SQL Language
 
ORDS - Oracle REST Data Services
ORDS - Oracle REST Data ServicesORDS - Oracle REST Data Services
ORDS - Oracle REST Data Services
 
Oracle SQL Tuning for Day-to-Day Data Warehouse Support
Oracle SQL Tuning for Day-to-Day Data Warehouse SupportOracle SQL Tuning for Day-to-Day Data Warehouse Support
Oracle SQL Tuning for Day-to-Day Data Warehouse Support
 

Similar to Analytical Functions for DWH

SQA server performance tuning
SQA server performance tuningSQA server performance tuning
SQA server performance tuning
Duy Tan Geek
 
SQL Server 2000 Research Series - Transact SQL
SQL Server 2000 Research Series - Transact SQLSQL Server 2000 Research Series - Transact SQL
SQL Server 2000 Research Series - Transact SQL
Jerry Yang
 
Developers' New features of Sql server express 2012
Developers' New features of Sql server express 2012Developers' New features of Sql server express 2012
Developers' New features of Sql server express 2012
Ziaur Rahman
 

Similar to Analytical Functions for DWH (20)

Db presn(1)
Db presn(1)Db presn(1)
Db presn(1)
 
Oracle Advanced SQL
Oracle Advanced SQLOracle Advanced SQL
Oracle Advanced SQL
 
Tony jambu (obscure) tools of the trade for tuning oracle sq ls
Tony jambu   (obscure) tools of the trade for tuning oracle sq lsTony jambu   (obscure) tools of the trade for tuning oracle sq ls
Tony jambu (obscure) tools of the trade for tuning oracle sq ls
 
Nose Dive into Apache Spark ML
Nose Dive into Apache Spark MLNose Dive into Apache Spark ML
Nose Dive into Apache Spark ML
 
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?
 
SQA server performance tuning
SQA server performance tuningSQA server performance tuning
SQA server performance tuning
 
Stored procedure with cursor
Stored procedure with cursorStored procedure with cursor
Stored procedure with cursor
 
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
 
Performance Instrumentation for PL/SQL: When, Why, How
Performance Instrumentation for PL/SQL: When, Why, HowPerformance Instrumentation for PL/SQL: When, Why, How
Performance Instrumentation for PL/SQL: When, Why, How
 
SQL Server 2000 Research Series - Transact SQL
SQL Server 2000 Research Series - Transact SQLSQL Server 2000 Research Series - Transact SQL
SQL Server 2000 Research Series - Transact SQL
 
SQL Tunning
SQL TunningSQL Tunning
SQL Tunning
 
Chapter15
Chapter15Chapter15
Chapter15
 
Developers' New features of Sql server express 2012
Developers' New features of Sql server express 2012Developers' New features of Sql server express 2012
Developers' New features of Sql server express 2012
 
Window functions with SQL Server 2016
Window functions with SQL Server 2016Window functions with SQL Server 2016
Window functions with SQL Server 2016
 
From Academic Papers To Production : A Learning To Rank Story
From Academic Papers To Production : A Learning To Rank StoryFrom Academic Papers To Production : A Learning To Rank Story
From Academic Papers To Production : A Learning To Rank Story
 
Sql storeprocedure
Sql storeprocedureSql storeprocedure
Sql storeprocedure
 
Sql and PL/SQL Best Practices I
Sql and PL/SQL Best Practices ISql and PL/SQL Best Practices I
Sql and PL/SQL Best Practices I
 
Consultas con agrupaci¾n de datos
Consultas con agrupaci¾n de datosConsultas con agrupaci¾n de datos
Consultas con agrupaci¾n de datos
 
resource governor
resource governorresource governor
resource governor
 

Recently uploaded

Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
amitlee9823
 
➥🔝 7737669865 🔝▻ Dindigul Call-girls in Women Seeking Men 🔝Dindigul🔝 Escor...
➥🔝 7737669865 🔝▻ Dindigul Call-girls in Women Seeking Men  🔝Dindigul🔝   Escor...➥🔝 7737669865 🔝▻ Dindigul Call-girls in Women Seeking Men  🔝Dindigul🔝   Escor...
➥🔝 7737669865 🔝▻ Dindigul Call-girls in Women Seeking Men 🔝Dindigul🔝 Escor...
amitlee9823
 
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
amitlee9823
 
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
amitlee9823
 
Call Girls In Attibele ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Attibele ☎ 7737669865 🥵 Book Your One night StandCall Girls In Attibele ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Attibele ☎ 7737669865 🥵 Book Your One night Stand
amitlee9823
 
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
amitlee9823
 
Call Girls In Hsr Layout ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Hsr Layout ☎ 7737669865 🥵 Book Your One night StandCall Girls In Hsr Layout ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Hsr Layout ☎ 7737669865 🥵 Book Your One night Stand
amitlee9823
 
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
amitlee9823
 
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
amitlee9823
 
Call Girls Indiranagar Just Call 👗 9155563397 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 9155563397 👗 Top Class Call Girl Service B...Call Girls Indiranagar Just Call 👗 9155563397 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 9155563397 👗 Top Class Call Girl Service B...
only4webmaster01
 
➥🔝 7737669865 🔝▻ Bangalore Call-girls in Women Seeking Men 🔝Bangalore🔝 Esc...
➥🔝 7737669865 🔝▻ Bangalore Call-girls in Women Seeking Men  🔝Bangalore🔝   Esc...➥🔝 7737669865 🔝▻ Bangalore Call-girls in Women Seeking Men  🔝Bangalore🔝   Esc...
➥🔝 7737669865 🔝▻ Bangalore Call-girls in Women Seeking Men 🔝Bangalore🔝 Esc...
amitlee9823
 
Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...
Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...
Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...
amitlee9823
 

Recently uploaded (20)

Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
 
Discover Why Less is More in B2B Research
Discover Why Less is More in B2B ResearchDiscover Why Less is More in B2B Research
Discover Why Less is More in B2B Research
 
BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort Service
BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort ServiceBDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort Service
BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort Service
 
➥🔝 7737669865 🔝▻ Dindigul Call-girls in Women Seeking Men 🔝Dindigul🔝 Escor...
➥🔝 7737669865 🔝▻ Dindigul Call-girls in Women Seeking Men  🔝Dindigul🔝   Escor...➥🔝 7737669865 🔝▻ Dindigul Call-girls in Women Seeking Men  🔝Dindigul🔝   Escor...
➥🔝 7737669865 🔝▻ Dindigul Call-girls in Women Seeking Men 🔝Dindigul🔝 Escor...
 
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
 
DATA SUMMIT 24 Building Real-Time Pipelines With FLaNK
DATA SUMMIT 24  Building Real-Time Pipelines With FLaNKDATA SUMMIT 24  Building Real-Time Pipelines With FLaNK
DATA SUMMIT 24 Building Real-Time Pipelines With FLaNK
 
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
 
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 nightCheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
 
Call Girls In Attibele ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Attibele ☎ 7737669865 🥵 Book Your One night StandCall Girls In Attibele ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Attibele ☎ 7737669865 🥵 Book Your One night Stand
 
VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...
VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...
VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...
 
Thane Call Girls 7091864438 Call Girls in Thane Escort service book now -
Thane Call Girls 7091864438 Call Girls in Thane Escort service book now -Thane Call Girls 7091864438 Call Girls in Thane Escort service book now -
Thane Call Girls 7091864438 Call Girls in Thane Escort service book now -
 
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
 
Call Girls In Hsr Layout ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Hsr Layout ☎ 7737669865 🥵 Book Your One night StandCall Girls In Hsr Layout ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Hsr Layout ☎ 7737669865 🥵 Book Your One night Stand
 
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
 
hybrid Seed Production In Chilli & Capsicum.pptx
hybrid Seed Production In Chilli & Capsicum.pptxhybrid Seed Production In Chilli & Capsicum.pptx
hybrid Seed Production In Chilli & Capsicum.pptx
 
Capstone Project on IBM Data Analytics Program
Capstone Project on IBM Data Analytics ProgramCapstone Project on IBM Data Analytics Program
Capstone Project on IBM Data Analytics Program
 
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
 
Call Girls Indiranagar Just Call 👗 9155563397 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 9155563397 👗 Top Class Call Girl Service B...Call Girls Indiranagar Just Call 👗 9155563397 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 9155563397 👗 Top Class Call Girl Service B...
 
➥🔝 7737669865 🔝▻ Bangalore Call-girls in Women Seeking Men 🔝Bangalore🔝 Esc...
➥🔝 7737669865 🔝▻ Bangalore Call-girls in Women Seeking Men  🔝Bangalore🔝   Esc...➥🔝 7737669865 🔝▻ Bangalore Call-girls in Women Seeking Men  🔝Bangalore🔝   Esc...
➥🔝 7737669865 🔝▻ Bangalore Call-girls in Women Seeking Men 🔝Bangalore🔝 Esc...
 
Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...
Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...
Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...
 

Analytical Functions for DWH

  • 1. Analytical Functions For DWH Emrah METE i2i-Systems Expert Analyst&Developer TROUG – BI/DW SIG Day 2014 03.04.2014 İTÜ
  • 2. http://emrahmete.wordpress.com/about/ Marmara Üniversitesi - Bilgisayar Teknolojisi ve Programlama Yıldız Teknik Üniversitesi - Bilgisayar Mühendisliği i2i-Systems – Analyst&Developer emrahmete.wordpress.com TROUG - Yönetim Kurulu Üyeliği Emrah METE Yahoo OracleTurk Grubu Moderatör Oracle Certified Expert
  • 3. Agenda • Analytical Functions..Why? • Aggregate and Analytic • First/Last Value • LAG/LEAD • Pivoting Operations • Ranking • Oracle Pattern Matching • Questions and Answers
  • 4.
  • 5.
  • 8. Aggregation (Step 1 - Traditional) SQL> select department_id, sum(salary) from employees group by department_id;
  • 9. Aggregation (Step 2 - Analytic) SQL> select first_name, salary, sum(salary) over (order by first_name) as empsal from employees;
  • 10. Aggregation (Step 2 - Analytic) SQL> select first_name, department_id, sum(salary) over (partition by department_id order by salary) as deptsal from employees order by department_id;
  • 11. Aggregation (Step 3 - Windowing) SQL> select employee_id, first_name, salary, sum(salary) over ( order by employee_id rows between unbounded preceding and current row) as cumul from employees order by employee_id;
  • 12. Aggregation (Step 3 - Windowing) SQL> select employee_id, first_name, salary, sum(salary) over ( order by employee_id rows between 1preceding and 1 following) as cumul from employees order by employee_id;
  • 13. Aggregation (Step 3 - Windowing)
  • 14. First_Value SQL> select first_name, department_id, first_value(salary) over (partition by department_id order by employee_id) as deptsal from employees order by department_id;
  • 15. Last_Value SQL> select first_name, department_id, salary, last_value(salary) over (partition by department_id order by department_id) as deptsal from employees order by department_id;
  • 16. LAG & LEAD SQL> select employee_id, first_name, salary, LAG (salary, 1) OVER (ORDER BY salary ) AS LAG1 FROM employees;
  • 17. LAG & LEAD SQL> select employee_id, first_name, salary, LEAD (salary, 1) OVER (ORDER BY salary ) AS LAG1 FROM employees;
  • 18. LISTAGG SQL> select department_id, listagg(first_name,’, ’) within group (order by department_id) as newList FROM employees group by department_id;
  • 21. Ranking – (Rank) SQL> SELECT department_id, last_name, salary, RANK() OVER (PARTITION BY department_id ORDER BY salary DESC) "Rank" FROM employees WHERE department_id = 60 ORDER BY department_id, "Rank", salary;
  • 22. Ranking – (Dense Rank) SQL> SELECT department_id, last_name, salary, RANK () OVER (PARTITION BY department_id ORDER BY salary DESC) "Rank", DENSE_RANK () OVER (PARTITION BY department_id ORDER BY salary DESC) "Drank" FROM employees WHERE department_id = 60 ORDER BY "Rank";
  • 23. Ranking – (Percent Rank) SQL> SELECT department_id, last_name, salary, PERCENT_RANK () OVER (PARTITION BY department_id ORDER BY salary) AS pr FROM employees WHERE department_id = 60 ORDER BY department_id, pr; (rank of row in its partition - 1) / (number of rows in the partition - 1) Example: Last_Name: Ernst (4 - 1) / (5 - 1) = 0,75
  • 24. - Financial applications seeking patterns of pricing, trading volume, and other behavior - Security applications where unusual behavior must be detected. - Fraud Detection - Sensor Data analysis.(CEP App.) Pattern Matching
  • 28. References http://connormcdonald.wordpress.com/ http://allthingsoracle.com/experts/alex-nuijten/ Dan Stober [ORACLE ANALYTIC FUNCTIONS WINDOWING CLAUSE] http://docs.oracle.com/cd/E16655_01/server.121/e17749/toc.htm http://www.oracle.com/technetwork/database/bi-datawarehousing/sql-analytics-index- 1984365.html http://docs.oracle.com/cd/B19306_01/server.102/b14200/functions056.htm http://docs.oracle.com/cd/E16655_01/server.121/e17749/analysis.htm#DWHSG0202 http://docs.oracle.com/cd/B19306_01/server.102/b14200/functions101.htm http://www.oracle.com/technetwork/database/bi-datawarehousing/sql-analytics-index- 1984365.html