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
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;
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