SlideShare una empresa de Scribd logo
1 de 56
Zohar Elkayam
www.realdbamagic.com
Twitter: @realmgic
Exploring Advanced SQL
Techniques Using
Analytic Functions
Who am I?
• Zohar Elkayam, CTO at Brillix
• DBA, team leader, database trainer, public speaker, and a
senior consultant for over 18 years
• Oracle ACE Associate
• Involved with Big Data projects since 2011
• Blogger – www.realdbamagic.com and www.ilDBA.co.il
2
About Brillix
• Brillix is a leading company that specialized in Data
Management
• We provide consulting, training, and professional services for
various Databases, Security, NoSQL, and Big Data solutions
• Providing the Brillix Big Data Experience Center
3
Agenda: Advanced SQL
• “Basic” aggregation: Rollup, Cube, and Grouping Sets
• Analytic functions
• Reporting Functions
• Ranking Functions
• Inter-row Functions
• Using the Window clause
• Oracle 12c new features overview
• Top-N queries
• Pattern matching
4
Advanced Aggregation
Functions
More than just group by…
5
Basics
• Group functions will return a single row for each group of rows
• We can run group functions only when we group the rest of the
columns together using GROUP BY clause
• Common group functions: SUM, MIN, MAX, AVG, etc.
• We can filter out rows after aggregation, if we use the HAVING
clause
6
GROUP BY With the ROLLUP and CUBE
Operators
• Use ROLLUP or CUBE with GROUP BY to produce super
aggregate rows by cross-referencing columns
• ROLLUP grouping produces a result set containing the regular
grouped rows and the subtotal and grand total values
• CUBE grouping produces a result set containing the rows from
ROLLUP and cross-tabulation rows
7
Using the ROLLUP Operator
• ROLLUP is an extension of the GROUP BY clause
• Use the ROLLUP operation to produce cumulative aggregates,
such as subtotals
SELECT [column,] group_function(column). . .
FROM table
[WHERE condition]
[GROUP BY [ROLLUP] group_by_expression]
[HAVING having_expression];
[ORDER BY column];
8
Using the ROLLUP Operator: Example
SELECT department_id, job_id, SUM(salary)
FROM hr.employees
WHERE department_id < 60
GROUP BY ROLLUP(department_id, job_id);
1
2
3
Total by DEPARTMENT_ID
and JOB_ID
Total by DEPARTMENT_ID
Grand total
9
Using the CUBE Operator
• CUBE is an extension of the GROUP BY clause
• You can use the CUBE operator to produce cross-tabulation
values with a single SELECT statement
SELECT [column,] group_function(column)...
FROM table
[WHERE condition]
[GROUP BY [CUBE] group_by_expression]
[HAVING having_expression]
[ORDER BY column];
10
1
2
3
4
Grand total
Total by JOB_ID
Total by DEPARTMENT_ID
and JOB_ID
Total by DEPARTMENT_ID
SELECT department_id, job_id, SUM(salary)
FROM hr.employees
WHERE department_id < 60
GROUP BY CUBE (department_id, job_id);
. . .
Using the CUBE Operator: Example
11
GROUPING SETS
• The GROUPING SETS syntax is used to define multiple
groupings in the same query
• All groupings specified in the GROUPING SETS clause are
computed and the results of individual groupings are combined
with a UNION ALL operation
• Grouping set efficiency:
• Only one pass over the base table is required
• There is no need to write complex UNION statements
• The more elements GROUPING SETS has, the greater the performance
benefit
12
SELECT department_id, job_id,
manager_id, AVG(salary)
FROM hr.employees
GROUP BY GROUPING SETS
((department_id,job_id), (job_id,manager_id));
GROUPING SETS: Example
. . .
. . .
1
2
13
Composite Columns
• A composite column is a collection of columns that are treated
as a unit.
ROLLUP (a,(b,c), d)
• Use parentheses within the GROUP BY clause to group columns,
so that they are treated as a unit while computing ROLLUP or
CUBE operators.
• When used with ROLLUP or CUBE, composite columns require
skipping aggregation across certain levels.
14
SELECT department_id, job_id, manager_id,
SUM(salary)
FROM hr.employees
GROUP BY ROLLUP( department_id,(job_id, manager_id));
Composite Columns: Example
…
1
2
3
4
15
Analytic Functions
Let’s analyze our data!
Overview of SQL for Analysis and Reporting
• Oracle has enhanced SQL's analytical processing capabilities
by introducing a family of analytic SQL functions
• These analytic functions enable you to calculate and perform:
• Reporting operations
• Rankings and percentiles
• Moving window calculations
• Inter-row calculations (LAG/LEAD, FIRST/LAST etc.)
• Pivoting operations (11g)
• Pattern matching (12c)
• Linear regression and predictions
17
Why Use Analytic Functions?
• Ability to see one row from another row in the results
• Avoid self-join queries
• Summary data in detail rows
• Slice and dice within the results
• Performance improvement, in some cases
18
Concepts Used in Analytic Functions
• Result set partitions: These are created and available to any
aggregate results such as sums and averages. The term
“partitions” is unrelated to the table partitions feature.
• Window: For each row in a partition, you can define a sliding
window of data, which determines the range of rows used to
perform the calculations for the current row.
• Current row: Each calculation performed with an analytic
function is based on a current row within a partition. It serves as
the reference point determining the start and end of the window.
19
Reporting Functions
• We can use aggregative functions as analytic functions (i.e.
SUM, AVG, MIN, MAX, COUNT etc.)
• Each row will get the aggregative value for a given partition
without the need for group by clause so we can have multiple
group by’s on the same row
• Getting the raw data along with the aggregated value
• Use Order By to get cumulative aggrigations
20
Report Functions
21
SELECT last_name, salary, department_id,
ROUND(AVG(salary) OVER (PARTITION BY department_id),2) A,
COUNT(*) OVER (PARTITION BY manager_id) B,
SUM(salary) OVER (PARTITION BY department_id ORDER BY salary) C,
MAX(salary) OVER () D
FROM hr.employees;
Ranking Functions
22
Using the Ranking Functions
• A ranking function computes the rank of a record compared to
other records in the data set based on the values of a set of
measures. The types of ranking function are:
• RANK and DENSE_RANK functions
• ROW_NUMBER function
• PERCENT_RANK function
• NTILE function
23
Working with the RANK Function
• The RANK function calculates the rank of a value in a group of values,
which is useful for top-N and bottom-N reporting.
• When using the RANK function, ascending is the default sort order,
which you can change to descending.
• Rows with equal values for the ranking criteria receive the same rank.
• Oracle Database then adds the number of tied rows to the tied rank to
calculate the next rank.
RANK ( ) OVER ( [query_partition_clause] order_by_clause )
24
Using the RANK Function: Example
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;
25
RANK and DENSE_RANK Functions: Example
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 department_id, last_name, salary DESC, "Rank"
DESC;
DENSE_RANK ( ) OVER ([query_partition_clause] order_by_clause)
26
Working with the ROW_NUMBER Function
• The ROW_NUMBER function calculates a sequential number of
a value in a group of values.
• When using the ROW_NUMBER function, ascending is the
default sort order, which you can change to descending.
• Rows with equal values for the ranking criteria receive a
different number.
ROW_NUMBER ( ) OVER ( [query_partition_clause] order_by_clause )
27
ROW_NUMBER vs. ROWNUM
• ROWNUM is a pseudo column, ROW_NUMBER is an actual
function
• It is calculated when the result returns to the client
• ROWNUM requires sorting of the entire dataset in order to
return an ordered list
• ROW_NUMBER will only sort the required rows thus giving
better performance
28
Using the PERCENT_RANK Function
• Uses rank values in its numerator and returns the percent rank of a
value relative to a group of values
• PERCENT_RANK of a row is calculated as follows:
• The range of values returned by PERCENT_RANK is 0 to 1,
inclusive. The first row in any set has a PERCENT_RANK of 0. The
return value is NUMBER. Its syntax is:
(rank of row in its partition - 1) /
(number of rows in the partition - 1)
PERCENT_RANK () OVER ([query_partition_clause]
order_by_clause)
29
Using the PERCENT_RANK Function:
Example
SELECT department_id, last_name, salary, PERCENT_RANK()
OVER (PARTITION BY department_id ORDER BY salary DESC)
AS pr
FROM hr.employees
ORDER BY department_id, pr, salary;
. . .
30
Working with the NTILE Function
• Not really a rank function
• Divides an ordered data set into a number of buckets indicated by
expr and assigns the appropriate bucket number to each row
• The buckets are numbered 1 through expr
NTILE ( expr ) OVER ([query_partition_clause] order_by_clause)
31
Summary of Ranking Functions
• Different ranking functions may return different results if the
data has ties
SELECT last_name, salary, department_id,
ROW_NUMBER() OVER (PARTITION BY department_id ORDER BY salary DESC) A,
RANK() OVER (PARTITION BY department_id ORDER BY salary DESC) B,
DENSE_RANK() OVER (PARTITION BY department_id ORDER BY salary DESC) C,
PERCENT_RANK() OVER (PARTITION BY department_id ORDER BY salary DESC) D,
NTILE(4) OVER (PARTITION BY department_id ORDER BY salary DESC) E
FROM hr.employees;
32
Inter-row Analytic Functions
33
Using the LAG and LEAD Analytic Functions
• LAG provides access to more than one row of a table at the same
time without a self-join.
• Given a series of rows returned from a query and a position of the
cursor, LAG provides access to a row at a given physical offset
before that position.
• If you do not specify the offset, its default is 1.
• If the offset goes beyond the scope of the window, the optional
default value is returned. If you do not specify the default, its value is
NULL.
{LAG | LEAD}(value_expr [, offset ] [, default ])
OVER ([ query_partition_clause ] order_by_clause)
34
Using the LAG and LEAD Analytic Functions:
Example
SELECT time_id, TO_CHAR(SUM(amount_sold),'9,999,999') AS SALES,
TO_CHAR(LAG(SUM(amount_sold),1) OVER (ORDER BY
time_id),'9,999,999') AS LAG1,
TO_CHAR(LEAD(SUM(amount_sold),1) OVER (ORDER BY
time_id),'9,999,999') AS LEAD1
FROM sales
WHERE time_id >= TO_DATE('10-OCT-2000') AND
time_id <= TO_DATE('14-OCT-2000')
GROUP BY time_id;
35
Using FIRST_VALUE/LAST_VALUE
• Returns the first/last value in an ordered set of values
• If the first value in the set is null, then the function returns NULL
unless you specify IGNORE NULLS. This setting is useful for
data densification.
38
FIRST_VALUE (expr [ IGNORE NULLS ]) OVER (analytic_clause)
LAST_VALUE (expr [ IGNORE NULLS ]) OVER (analytic_clause)
Using FIRST_VALUE Analytic Function
Example
SELECT department_id, last_name, salary,
FIRST_VALUE(last_name) OVER
(ORDER BY salary ASC ROWS UNBOUNDED PRECEDING) AS lowest_sal,
LAST_VALUE(last_name) OVER (ORDER BY salary ASC ROWS BETWEEN UNBOUNDED
PRECEDING and UNBOUNDED FOLLOWING) AS highest_sal
FROM (SELECT * FROM employees WHERE department_id = 30 ORDER BY employee_id)
ORDER BY department_id, last_name, salary;
39
Using NTH_VALUE Analytic Function
• Returns the N-th values in an ordered set of values
• Different default window: RANGE BETWEEN UNBOUNDED
PRECEDING AND CURRENT ROW
NTH_VALUE (measure_expr, n)
[ FROM { FIRST | LAST } ][ { RESPECT | IGNORE } NULLS ]
OVER (analytic_clause)
40
Using NTH_VALUE Analytic Function
Example
SELECT prod_id, channel_id, MIN(amount_sold),
NTH_VALUE ( MIN(amount_sold), 2) OVER (PARTITION BY
prod_id ORDER BY channel_id
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED
FOLLOWING) nv
FROM sh.sales
WHERE prod_id BETWEEN 13 and 16
GROUP BY prod_id, channel_id;
41
Using the LISTAGG Function
• For a specified measure, LISTAGG orders data within each group
specified in the ORDER BY clause and then concatenates the
values of the measure column
• WARNING: Limited to output of 4000 chars (else, error message
in runtime)
42
LISTAGG(measure_expr [, 'delimiter'])
WITHIN GROUP (order_by_clause) [OVER
query_partition_clause]
Using the LISTAGG Function Example
SELECT department_id "Dept", hire_date "Date",
last_name "Name",
LISTAGG(last_name, ', ') WITHIN GROUP (ORDER BY
hire_date, last_name)
OVER (PARTITION BY department_id) as "Emp_list"
FROM hr.employees
WHERE hire_date < '01-SEP-2003'
ORDER BY "Dept", "Date", "Name";
43
Window Functions
Window Functions
• The windowing_clause gives some analytic functions a
further degree of control over this window within the current
partition
• The windowing_clause can only be used if an
order_by_clause is present
• The windows are always limited to the current partition
• Generally, the default window is the entire work set unless said
otherwise
45
Windowing Clause Useful Usages
• Cumulative aggregation
• Sliding average over proceeding and/or following rows
• Using the RANGE parameter to filter aggregation records
46
Windows can be by RANGE or ROWS
47
Possible values for start_point and end_point
UNBOUNDED PRECEDING The window starts at the first row of the partition. Only
available for start points.
UNBOUNDED FOLLOWING The window ends at the last row of the partition. Only
available for end points.
CURRENT ROW The window starts or ends at the current row
value_expr PRECEDING A physical or logical offset before the current row.
When used with RANGE, can also be an interval literal
value_expr FOLLOWING As above, but an offset after the current row
RANGE BETWEEN start_point AND end_point
ROWS BETWEEN start_point AND end_point
Shortcuts
• Useful shortcuts for the windowing clause:
48
ROWS UNBOUNDED PRECEDING ROWS BETWEEN UNBOUNDED
PRECEDING AND CURRENT
ROW
ROWS 10 PRECEDING ROWS BETWEEN 10
PRECEDING AND CURRENT
ROW
ROWS CURRENT ROW ROWS BETWEEN CURRENT
ROW AND CURRENT ROW (1
row)
Oracle 12c New Feature
Overview
Just a couple, we can talk for hours on all the new features.. 
49
What’s New in Oracle 12c
• Top-N Queries and pagination: returning the top-n queries
• syntactic honey – just a syntax enhancement, not performance
enhancement
• Pattern matching: New MATCH_RECOGNIZE syntax for finding
row between patterns
50
Top-N Examples
51
SELECT last_name, salary
FROM hr.employees
ORDER BY salary
FETCH FIRST 4 ROWS ONLY;
SELECT last_name, salary
FROM hr.employees
ORDER BY salary
FETCH FIRST 4 ROWS WITH TIES;
SELECT last_name, salary
FROM hr.employees
ORDER BY salary DESC
FETCH FIRST 10 PERCENT ROWS ONLY;
What is Pattern Matching?
• A new syntax that allows us to identify and group rows with
consecutive values
• Consecutive in this regards – row after row
• Uses regular expression like syntax to find patterns
• Finds complex behavior we couldn’t found before, or needed
PL/SQL for it
52
Example: Pages in a Book Example
• Our goal: find uninterrupted sequences in a book
• This can be useful for detecting missing records or sequential
behavior
53
(source: “Database 12c Row Pattern Matching” (OOW2014 session), by Stew Ashton).
SELECT *
FROM book_pages
MATCH_RECOGNIZE (
ORDER BY page
PATTERN (A B*)
DEFINE B AS page = PREV(page)+1
ONE ROW PER MATCH
MEASURES
A.page firstpage,
LAST(page) lastpage,
COUNT(*) cnt
AFTER MATCH SKIP PAST LAST ROW
);
1. Define input
2. Pattern Matching
3. Order input
4. Process pattern
5. Using defined conditions
6. Output: rows per match
7. Output: columns per row
8. Where to go after
match?
Pattern Matching Example
SELECT *
FROM book_pages
MATCH_RECOGNIZE (
ORDER BY page
MEASURES
A.page firstpage,
LAST(page) lastpage,
COUNT(*) cnt
ONE ROW PER MATCH
AFTER MATCH SKIP PAST LAST ROW
PATTERN (A B*)
DEFINE B AS page = PREV(page)+1
);
And the Result…
55
FIRSTPAGE LASTPAGE CNT
---------- ---------- ----------
1 3 3
5 7 3
10 15 6
42 42 1
Q&A
56
Summary
• We talked about advanced aggregation clauses, multi- dimensional
aggregation, and how utilizing it can save us time and effort
• Analytic functions are really important both for performance and for
code clarity
• We saw how rank function work and how to use windows
• We explored some Oracle 12c enhancements – more information
about that can be found in my blog: www.realdbamgic.com
57
Thank You!
Zohar Elkayam
twitter: @realmgic
Zohar@Brillix.co.il
www.realdbamagic.com
58

Más contenido relacionado

La actualidad más candente

Advanced PLSQL Optimizing for Better Performance
Advanced PLSQL Optimizing for Better PerformanceAdvanced PLSQL Optimizing for Better Performance
Advanced PLSQL Optimizing for Better PerformanceZohar Elkayam
 
Advanced PL/SQL Optimizing for Better Performance 2016
Advanced PL/SQL Optimizing for Better Performance 2016Advanced PL/SQL Optimizing for Better Performance 2016
Advanced PL/SQL Optimizing for Better Performance 2016Zohar Elkayam
 
Optimizer overviewoow2014
Optimizer overviewoow2014Optimizer overviewoow2014
Optimizer overviewoow2014Mysql User Camp
 
MySQL Indexing : Improving Query Performance Using Index (Covering Index)
MySQL Indexing : Improving Query Performance Using Index (Covering Index)MySQL Indexing : Improving Query Performance Using Index (Covering Index)
MySQL Indexing : Improving Query Performance Using Index (Covering Index)Hemant Kumar Singh
 
MySQL: Indexing for Better Performance
MySQL: Indexing for Better PerformanceMySQL: Indexing for Better Performance
MySQL: Indexing for Better Performancejkeriaki
 
Indexing the MySQL Index: Key to performance tuning
Indexing the MySQL Index: Key to performance tuningIndexing the MySQL Index: Key to performance tuning
Indexing the MySQL Index: Key to performance tuningOSSCube
 
MySQL Performance Tips & Best Practices
MySQL Performance Tips & Best PracticesMySQL Performance Tips & Best Practices
MySQL Performance Tips & Best PracticesIsaac Mosquera
 
MySQL Performance Schema in Action: the Complete Tutorial
MySQL Performance Schema in Action: the Complete TutorialMySQL Performance Schema in Action: the Complete Tutorial
MySQL Performance Schema in Action: the Complete TutorialSveta Smirnova
 
MySQL Performance Schema in Action
MySQL Performance Schema in ActionMySQL Performance Schema in Action
MySQL Performance Schema in ActionSveta Smirnova
 
MySQL Indexing - Best practices for MySQL 5.6
MySQL Indexing - Best practices for MySQL 5.6MySQL Indexing - Best practices for MySQL 5.6
MySQL Indexing - Best practices for MySQL 5.6MYXPLAIN
 
Optimizing MySQL Queries
Optimizing MySQL QueriesOptimizing MySQL Queries
Optimizing MySQL QueriesAchievers Tech
 
B+Tree Indexes and InnoDB
B+Tree Indexes and InnoDBB+Tree Indexes and InnoDB
B+Tree Indexes and InnoDBOvais Tariq
 
How to analyze and tune sql queries for better performance percona15
How to analyze and tune sql queries for better performance percona15How to analyze and tune sql queries for better performance percona15
How to analyze and tune sql queries for better performance percona15oysteing
 
MySQL Optimizer Cost Model
MySQL Optimizer Cost ModelMySQL Optimizer Cost Model
MySQL Optimizer Cost ModelOlav Sandstå
 
9780538745840 ppt ch08
9780538745840 ppt ch089780538745840 ppt ch08
9780538745840 ppt ch08Terry Yoast
 
New SQL features in latest MySQL releases
New SQL features in latest MySQL releasesNew SQL features in latest MySQL releases
New SQL features in latest MySQL releasesGeorgi Sotirov
 
How to analyze and tune sql queries for better performance
How to analyze and tune sql queries for better performanceHow to analyze and tune sql queries for better performance
How to analyze and tune sql queries for better performanceoysteing
 

La actualidad más candente (19)

Advanced PLSQL Optimizing for Better Performance
Advanced PLSQL Optimizing for Better PerformanceAdvanced PLSQL Optimizing for Better Performance
Advanced PLSQL Optimizing for Better Performance
 
Olapsql
OlapsqlOlapsql
Olapsql
 
Advanced PL/SQL Optimizing for Better Performance 2016
Advanced PL/SQL Optimizing for Better Performance 2016Advanced PL/SQL Optimizing for Better Performance 2016
Advanced PL/SQL Optimizing for Better Performance 2016
 
Optimizer overviewoow2014
Optimizer overviewoow2014Optimizer overviewoow2014
Optimizer overviewoow2014
 
MySQL Indexing : Improving Query Performance Using Index (Covering Index)
MySQL Indexing : Improving Query Performance Using Index (Covering Index)MySQL Indexing : Improving Query Performance Using Index (Covering Index)
MySQL Indexing : Improving Query Performance Using Index (Covering Index)
 
MySQL: Indexing for Better Performance
MySQL: Indexing for Better PerformanceMySQL: Indexing for Better Performance
MySQL: Indexing for Better Performance
 
Indexing the MySQL Index: Key to performance tuning
Indexing the MySQL Index: Key to performance tuningIndexing the MySQL Index: Key to performance tuning
Indexing the MySQL Index: Key to performance tuning
 
MySQL Performance Tips & Best Practices
MySQL Performance Tips & Best PracticesMySQL Performance Tips & Best Practices
MySQL Performance Tips & Best Practices
 
MySQL Performance Schema in Action: the Complete Tutorial
MySQL Performance Schema in Action: the Complete TutorialMySQL Performance Schema in Action: the Complete Tutorial
MySQL Performance Schema in Action: the Complete Tutorial
 
MySQL Performance Schema in Action
MySQL Performance Schema in ActionMySQL Performance Schema in Action
MySQL Performance Schema in Action
 
MySQL Indexing - Best practices for MySQL 5.6
MySQL Indexing - Best practices for MySQL 5.6MySQL Indexing - Best practices for MySQL 5.6
MySQL Indexing - Best practices for MySQL 5.6
 
Optimizing MySQL Queries
Optimizing MySQL QueriesOptimizing MySQL Queries
Optimizing MySQL Queries
 
B+Tree Indexes and InnoDB
B+Tree Indexes and InnoDBB+Tree Indexes and InnoDB
B+Tree Indexes and InnoDB
 
SQL Optimizer vs Hive
SQL Optimizer vs Hive SQL Optimizer vs Hive
SQL Optimizer vs Hive
 
How to analyze and tune sql queries for better performance percona15
How to analyze and tune sql queries for better performance percona15How to analyze and tune sql queries for better performance percona15
How to analyze and tune sql queries for better performance percona15
 
MySQL Optimizer Cost Model
MySQL Optimizer Cost ModelMySQL Optimizer Cost Model
MySQL Optimizer Cost Model
 
9780538745840 ppt ch08
9780538745840 ppt ch089780538745840 ppt ch08
9780538745840 ppt ch08
 
New SQL features in latest MySQL releases
New SQL features in latest MySQL releasesNew SQL features in latest MySQL releases
New SQL features in latest MySQL releases
 
How to analyze and tune sql queries for better performance
How to analyze and tune sql queries for better performanceHow to analyze and tune sql queries for better performance
How to analyze and tune sql queries for better performance
 

Destacado

Window functions in MariaDB 10.2
Window functions in MariaDB 10.2Window functions in MariaDB 10.2
Window functions in MariaDB 10.2Sergey Petrunya
 
Common Table Expressions in MariaDB 10.2 (Percona Live Amsterdam 2016)
Common Table Expressions in MariaDB 10.2 (Percona Live Amsterdam 2016)Common Table Expressions in MariaDB 10.2 (Percona Live Amsterdam 2016)
Common Table Expressions in MariaDB 10.2 (Percona Live Amsterdam 2016)Sergey Petrunya
 
Sql server scalability fundamentals
Sql server scalability fundamentalsSql server scalability fundamentals
Sql server scalability fundamentalsChris Adkin
 
Things Every Oracle DBA Needs To Know About The Hadoop Ecosystem
Things Every Oracle DBA Needs To Know About The Hadoop EcosystemThings Every Oracle DBA Needs To Know About The Hadoop Ecosystem
Things Every Oracle DBA Needs To Know About The Hadoop EcosystemZohar Elkayam
 
SQL Server - Constraints
SQL Server - ConstraintsSQL Server - Constraints
SQL Server - ConstraintsAaron Buma
 
ORACLE, SQL, PL/SQL Made very very Easy Happy Learning....
ORACLE, SQL, PL/SQL Made very very Easy Happy Learning....ORACLE, SQL, PL/SQL Made very very Easy Happy Learning....
ORACLE, SQL, PL/SQL Made very very Easy Happy Learning....Racharla Rohit Varma
 
Oracle Data Guard A to Z
Oracle Data Guard A to ZOracle Data Guard A to Z
Oracle Data Guard A to ZZohar Elkayam
 
Understanding oracle rac internals part 2 - slides
Understanding oracle rac internals   part 2 - slidesUnderstanding oracle rac internals   part 2 - slides
Understanding oracle rac internals part 2 - slidesMohamed Farouk
 
Oracle RAC Internals - The Cache Fusion Edition
Oracle RAC Internals - The Cache Fusion EditionOracle RAC Internals - The Cache Fusion Edition
Oracle RAC Internals - The Cache Fusion EditionMarkus Michalewicz
 
Understanding oracle rac internals part 1 - slides
Understanding oracle rac internals   part 1 - slidesUnderstanding oracle rac internals   part 1 - slides
Understanding oracle rac internals part 1 - slidesMohamed Farouk
 
Understanding Oracle RAC 11g Release 2 Internals
Understanding Oracle RAC 11g Release 2 InternalsUnderstanding Oracle RAC 11g Release 2 Internals
Understanding Oracle RAC 11g Release 2 InternalsMarkus Michalewicz
 
Oracle 12c New Features For Better Performance
Oracle 12c New Features For Better PerformanceOracle 12c New Features For Better Performance
Oracle 12c New Features For Better PerformanceZohar Elkayam
 
10 SQL Tricks that You Didn't Think Were Possible
10 SQL Tricks that You Didn't Think Were Possible10 SQL Tricks that You Didn't Think Were Possible
10 SQL Tricks that You Didn't Think Were PossibleLukas Eder
 
Oracle Sql Tuning
Oracle Sql TuningOracle Sql Tuning
Oracle Sql TuningChris Adkin
 
Starting small, thinking big
Starting small, thinking bigStarting small, thinking big
Starting small, thinking bigOluyomi Ojo
 
Oracle RAC 12c Release 2 - Overview
Oracle RAC 12c Release 2 - OverviewOracle RAC 12c Release 2 - Overview
Oracle RAC 12c Release 2 - OverviewMarkus Michalewicz
 

Destacado (17)

Window functions in MariaDB 10.2
Window functions in MariaDB 10.2Window functions in MariaDB 10.2
Window functions in MariaDB 10.2
 
Common Table Expressions in MariaDB 10.2 (Percona Live Amsterdam 2016)
Common Table Expressions in MariaDB 10.2 (Percona Live Amsterdam 2016)Common Table Expressions in MariaDB 10.2 (Percona Live Amsterdam 2016)
Common Table Expressions in MariaDB 10.2 (Percona Live Amsterdam 2016)
 
Sql server windowing functions
Sql server windowing functionsSql server windowing functions
Sql server windowing functions
 
Sql server scalability fundamentals
Sql server scalability fundamentalsSql server scalability fundamentals
Sql server scalability fundamentals
 
Things Every Oracle DBA Needs To Know About The Hadoop Ecosystem
Things Every Oracle DBA Needs To Know About The Hadoop EcosystemThings Every Oracle DBA Needs To Know About The Hadoop Ecosystem
Things Every Oracle DBA Needs To Know About The Hadoop Ecosystem
 
SQL Server - Constraints
SQL Server - ConstraintsSQL Server - Constraints
SQL Server - Constraints
 
ORACLE, SQL, PL/SQL Made very very Easy Happy Learning....
ORACLE, SQL, PL/SQL Made very very Easy Happy Learning....ORACLE, SQL, PL/SQL Made very very Easy Happy Learning....
ORACLE, SQL, PL/SQL Made very very Easy Happy Learning....
 
Oracle Data Guard A to Z
Oracle Data Guard A to ZOracle Data Guard A to Z
Oracle Data Guard A to Z
 
Understanding oracle rac internals part 2 - slides
Understanding oracle rac internals   part 2 - slidesUnderstanding oracle rac internals   part 2 - slides
Understanding oracle rac internals part 2 - slides
 
Oracle RAC Internals - The Cache Fusion Edition
Oracle RAC Internals - The Cache Fusion EditionOracle RAC Internals - The Cache Fusion Edition
Oracle RAC Internals - The Cache Fusion Edition
 
Understanding oracle rac internals part 1 - slides
Understanding oracle rac internals   part 1 - slidesUnderstanding oracle rac internals   part 1 - slides
Understanding oracle rac internals part 1 - slides
 
Understanding Oracle RAC 11g Release 2 Internals
Understanding Oracle RAC 11g Release 2 InternalsUnderstanding Oracle RAC 11g Release 2 Internals
Understanding Oracle RAC 11g Release 2 Internals
 
Oracle 12c New Features For Better Performance
Oracle 12c New Features For Better PerformanceOracle 12c New Features For Better Performance
Oracle 12c New Features For Better Performance
 
10 SQL Tricks that You Didn't Think Were Possible
10 SQL Tricks that You Didn't Think Were Possible10 SQL Tricks that You Didn't Think Were Possible
10 SQL Tricks that You Didn't Think Were Possible
 
Oracle Sql Tuning
Oracle Sql TuningOracle Sql Tuning
Oracle Sql Tuning
 
Starting small, thinking big
Starting small, thinking bigStarting small, thinking big
Starting small, thinking big
 
Oracle RAC 12c Release 2 - Overview
Oracle RAC 12c Release 2 - OverviewOracle RAC 12c Release 2 - Overview
Oracle RAC 12c Release 2 - Overview
 

Similar a Exploring Advanced SQL Techniques Using Analytic Functions

Advanced SQL For Data Scientists
Advanced SQL For Data ScientistsAdvanced SQL For Data Scientists
Advanced SQL For Data ScientistsDatabricks
 
2 sql - single-row functions
2   sql - single-row functions2   sql - single-row functions
2 sql - single-row functionsAnkit Dubey
 
Oracle_Analytical_function.pdf
Oracle_Analytical_function.pdfOracle_Analytical_function.pdf
Oracle_Analytical_function.pdfKalyankumarVenkat1
 
Using Excel Functions
Using Excel FunctionsUsing Excel Functions
Using Excel FunctionsGautam Gupta
 
it skill excel sheet for ppt.pptx
it skill excel sheet for ppt.pptxit skill excel sheet for ppt.pptx
it skill excel sheet for ppt.pptxMdAquibRazi1
 
Advanced functions in PL SQL
Advanced functions in PL SQLAdvanced functions in PL SQL
Advanced functions in PL SQLHosein Zare
 
Cubing and Metrics in SQL, oh my!
Cubing and Metrics in SQL, oh my!Cubing and Metrics in SQL, oh my!
Cubing and Metrics in SQL, oh my!Julian Hyde
 
Presentation interpreting execution plans for sql statements
Presentation    interpreting execution plans for sql statementsPresentation    interpreting execution plans for sql statements
Presentation interpreting execution plans for sql statementsxKinAnx
 
Business Intelligence Portfolio
Business Intelligence PortfolioBusiness Intelligence Portfolio
Business Intelligence PortfolioChris Seebacher
 
Creating other schema objects
Creating other schema objectsCreating other schema objects
Creating other schema objectsSyed Zaid Irshad
 
Python-for-Data-Analysis.pdf
Python-for-Data-Analysis.pdfPython-for-Data-Analysis.pdf
Python-for-Data-Analysis.pdfssuser598883
 
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 functionsClayton Groom
 
MYSQL single rowfunc-multirowfunc-groupby-having
MYSQL single rowfunc-multirowfunc-groupby-havingMYSQL single rowfunc-multirowfunc-groupby-having
MYSQL single rowfunc-multirowfunc-groupby-havingAhmed Farag
 

Similar a Exploring Advanced SQL Techniques Using Analytic Functions (20)

Advanced SQL For Data Scientists
Advanced SQL For Data ScientistsAdvanced SQL For Data Scientists
Advanced SQL For Data Scientists
 
2 sql - single-row functions
2   sql - single-row functions2   sql - single-row functions
2 sql - single-row functions
 
Oracle_Analytical_function.pdf
Oracle_Analytical_function.pdfOracle_Analytical_function.pdf
Oracle_Analytical_function.pdf
 
Using Excel Functions
Using Excel FunctionsUsing Excel Functions
Using Excel Functions
 
it skill excel sheet for ppt.pptx
it skill excel sheet for ppt.pptxit skill excel sheet for ppt.pptx
it skill excel sheet for ppt.pptx
 
Advanced functions in PL SQL
Advanced functions in PL SQLAdvanced functions in PL SQL
Advanced functions in PL SQL
 
Cubing and Metrics in SQL, oh my!
Cubing and Metrics in SQL, oh my!Cubing and Metrics in SQL, oh my!
Cubing and Metrics in SQL, oh my!
 
Presentation interpreting execution plans for sql statements
Presentation    interpreting execution plans for sql statementsPresentation    interpreting execution plans for sql statements
Presentation interpreting execution plans for sql statements
 
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
 
Les04
Les04Les04
Les04
 
Les17
Les17Les17
Les17
 
Business Intelligence Portfolio
Business Intelligence PortfolioBusiness Intelligence Portfolio
Business Intelligence Portfolio
 
Creating other schema objects
Creating other schema objectsCreating other schema objects
Creating other schema objects
 
SQL Windowing
SQL WindowingSQL Windowing
SQL Windowing
 
SQL Tunning
SQL TunningSQL Tunning
SQL Tunning
 
Python-for-Data-Analysis.pdf
Python-for-Data-Analysis.pdfPython-for-Data-Analysis.pdf
Python-for-Data-Analysis.pdf
 
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
 
Chapter15
Chapter15Chapter15
Chapter15
 
MYSQL single rowfunc-multirowfunc-groupby-having
MYSQL single rowfunc-multirowfunc-groupby-havingMYSQL single rowfunc-multirowfunc-groupby-having
MYSQL single rowfunc-multirowfunc-groupby-having
 
Oracle: Functions
Oracle: FunctionsOracle: Functions
Oracle: Functions
 

Más de Zohar Elkayam

Docker Concepts for Oracle/MySQL DBAs and DevOps
Docker Concepts for Oracle/MySQL DBAs and DevOpsDocker Concepts for Oracle/MySQL DBAs and DevOps
Docker Concepts for Oracle/MySQL DBAs and DevOpsZohar Elkayam
 
Oracle Database Performance Tuning Advanced Features and Best Practices for DBAs
Oracle Database Performance Tuning Advanced Features and Best Practices for DBAsOracle Database Performance Tuning Advanced Features and Best Practices for DBAs
Oracle Database Performance Tuning Advanced Features and Best Practices for DBAsZohar Elkayam
 
Things Every Oracle DBA Needs to Know About the Hadoop Ecosystem 20170527
Things Every Oracle DBA Needs to Know About the Hadoop Ecosystem 20170527Things Every Oracle DBA Needs to Know About the Hadoop Ecosystem 20170527
Things Every Oracle DBA Needs to Know About the Hadoop Ecosystem 20170527Zohar Elkayam
 
Things Every Oracle DBA Needs to Know About the Hadoop Ecosystem (c17lv version)
Things Every Oracle DBA Needs to Know About the Hadoop Ecosystem (c17lv version)Things Every Oracle DBA Needs to Know About the Hadoop Ecosystem (c17lv version)
Things Every Oracle DBA Needs to Know About the Hadoop Ecosystem (c17lv version)Zohar Elkayam
 
Introduction to Oracle Data Guard Broker
Introduction to Oracle Data Guard BrokerIntroduction to Oracle Data Guard Broker
Introduction to Oracle Data Guard BrokerZohar Elkayam
 
Exploring Oracle Multitenant in Oracle Database 12c
Exploring Oracle Multitenant in Oracle Database 12cExploring Oracle Multitenant in Oracle Database 12c
Exploring Oracle Multitenant in Oracle Database 12cZohar Elkayam
 
Rapid Cluster Computing with Apache Spark 2016
Rapid Cluster Computing with Apache Spark 2016Rapid Cluster Computing with Apache Spark 2016
Rapid Cluster Computing with Apache Spark 2016Zohar Elkayam
 
MySQL 5.7 New Features for Developers
MySQL 5.7 New Features for DevelopersMySQL 5.7 New Features for Developers
MySQL 5.7 New Features for DevelopersZohar Elkayam
 
Is SQLcl the Next Generation of SQL*Plus?
Is SQLcl the Next Generation of SQL*Plus?Is SQLcl the Next Generation of SQL*Plus?
Is SQLcl the Next Generation of SQL*Plus?Zohar Elkayam
 
Things Every Oracle DBA Needs to Know about the Hadoop Ecosystem
Things Every Oracle DBA Needs to Know about the Hadoop EcosystemThings Every Oracle DBA Needs to Know about the Hadoop Ecosystem
Things Every Oracle DBA Needs to Know about the Hadoop EcosystemZohar Elkayam
 
The Hadoop Ecosystem for Developers
The Hadoop Ecosystem for DevelopersThe Hadoop Ecosystem for Developers
The Hadoop Ecosystem for DevelopersZohar Elkayam
 
Big data for cio 2015
Big data for cio 2015Big data for cio 2015
Big data for cio 2015Zohar Elkayam
 
SQLcl the next generation of SQLPlus?
SQLcl the next generation of SQLPlus?SQLcl the next generation of SQLPlus?
SQLcl the next generation of SQLPlus?Zohar Elkayam
 
Adding real time reporting to your database oracle db in memory
Adding real time reporting to your database oracle db in memoryAdding real time reporting to your database oracle db in memory
Adding real time reporting to your database oracle db in memoryZohar Elkayam
 
Oracle Data Guard Broker Webinar
Oracle Data Guard Broker WebinarOracle Data Guard Broker Webinar
Oracle Data Guard Broker WebinarZohar Elkayam
 
Oracle Database In-Memory Option for ILOUG
Oracle Database In-Memory Option for ILOUGOracle Database In-Memory Option for ILOUG
Oracle Database In-Memory Option for ILOUGZohar Elkayam
 

Más de Zohar Elkayam (17)

Docker Concepts for Oracle/MySQL DBAs and DevOps
Docker Concepts for Oracle/MySQL DBAs and DevOpsDocker Concepts for Oracle/MySQL DBAs and DevOps
Docker Concepts for Oracle/MySQL DBAs and DevOps
 
Oracle Database Performance Tuning Advanced Features and Best Practices for DBAs
Oracle Database Performance Tuning Advanced Features and Best Practices for DBAsOracle Database Performance Tuning Advanced Features and Best Practices for DBAs
Oracle Database Performance Tuning Advanced Features and Best Practices for DBAs
 
Things Every Oracle DBA Needs to Know About the Hadoop Ecosystem 20170527
Things Every Oracle DBA Needs to Know About the Hadoop Ecosystem 20170527Things Every Oracle DBA Needs to Know About the Hadoop Ecosystem 20170527
Things Every Oracle DBA Needs to Know About the Hadoop Ecosystem 20170527
 
Things Every Oracle DBA Needs to Know About the Hadoop Ecosystem (c17lv version)
Things Every Oracle DBA Needs to Know About the Hadoop Ecosystem (c17lv version)Things Every Oracle DBA Needs to Know About the Hadoop Ecosystem (c17lv version)
Things Every Oracle DBA Needs to Know About the Hadoop Ecosystem (c17lv version)
 
Introduction to Oracle Data Guard Broker
Introduction to Oracle Data Guard BrokerIntroduction to Oracle Data Guard Broker
Introduction to Oracle Data Guard Broker
 
Exploring Oracle Multitenant in Oracle Database 12c
Exploring Oracle Multitenant in Oracle Database 12cExploring Oracle Multitenant in Oracle Database 12c
Exploring Oracle Multitenant in Oracle Database 12c
 
Rapid Cluster Computing with Apache Spark 2016
Rapid Cluster Computing with Apache Spark 2016Rapid Cluster Computing with Apache Spark 2016
Rapid Cluster Computing with Apache Spark 2016
 
MySQL 5.7 New Features for Developers
MySQL 5.7 New Features for DevelopersMySQL 5.7 New Features for Developers
MySQL 5.7 New Features for Developers
 
Is SQLcl the Next Generation of SQL*Plus?
Is SQLcl the Next Generation of SQL*Plus?Is SQLcl the Next Generation of SQL*Plus?
Is SQLcl the Next Generation of SQL*Plus?
 
Things Every Oracle DBA Needs to Know about the Hadoop Ecosystem
Things Every Oracle DBA Needs to Know about the Hadoop EcosystemThings Every Oracle DBA Needs to Know about the Hadoop Ecosystem
Things Every Oracle DBA Needs to Know about the Hadoop Ecosystem
 
The Hadoop Ecosystem for Developers
The Hadoop Ecosystem for DevelopersThe Hadoop Ecosystem for Developers
The Hadoop Ecosystem for Developers
 
Big data for cio 2015
Big data for cio 2015Big data for cio 2015
Big data for cio 2015
 
SQLcl the next generation of SQLPlus?
SQLcl the next generation of SQLPlus?SQLcl the next generation of SQLPlus?
SQLcl the next generation of SQLPlus?
 
Adding real time reporting to your database oracle db in memory
Adding real time reporting to your database oracle db in memoryAdding real time reporting to your database oracle db in memory
Adding real time reporting to your database oracle db in memory
 
Intro to Big Data
Intro to Big DataIntro to Big Data
Intro to Big Data
 
Oracle Data Guard Broker Webinar
Oracle Data Guard Broker WebinarOracle Data Guard Broker Webinar
Oracle Data Guard Broker Webinar
 
Oracle Database In-Memory Option for ILOUG
Oracle Database In-Memory Option for ILOUGOracle Database In-Memory Option for ILOUG
Oracle Database In-Memory Option for ILOUG
 

Último

A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 

Último (20)

A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 

Exploring Advanced SQL Techniques Using Analytic Functions

  • 1. Zohar Elkayam www.realdbamagic.com Twitter: @realmgic Exploring Advanced SQL Techniques Using Analytic Functions
  • 2. Who am I? • Zohar Elkayam, CTO at Brillix • DBA, team leader, database trainer, public speaker, and a senior consultant for over 18 years • Oracle ACE Associate • Involved with Big Data projects since 2011 • Blogger – www.realdbamagic.com and www.ilDBA.co.il 2
  • 3. About Brillix • Brillix is a leading company that specialized in Data Management • We provide consulting, training, and professional services for various Databases, Security, NoSQL, and Big Data solutions • Providing the Brillix Big Data Experience Center 3
  • 4. Agenda: Advanced SQL • “Basic” aggregation: Rollup, Cube, and Grouping Sets • Analytic functions • Reporting Functions • Ranking Functions • Inter-row Functions • Using the Window clause • Oracle 12c new features overview • Top-N queries • Pattern matching 4
  • 6. Basics • Group functions will return a single row for each group of rows • We can run group functions only when we group the rest of the columns together using GROUP BY clause • Common group functions: SUM, MIN, MAX, AVG, etc. • We can filter out rows after aggregation, if we use the HAVING clause 6
  • 7. GROUP BY With the ROLLUP and CUBE Operators • Use ROLLUP or CUBE with GROUP BY to produce super aggregate rows by cross-referencing columns • ROLLUP grouping produces a result set containing the regular grouped rows and the subtotal and grand total values • CUBE grouping produces a result set containing the rows from ROLLUP and cross-tabulation rows 7
  • 8. Using the ROLLUP Operator • ROLLUP is an extension of the GROUP BY clause • Use the ROLLUP operation to produce cumulative aggregates, such as subtotals SELECT [column,] group_function(column). . . FROM table [WHERE condition] [GROUP BY [ROLLUP] group_by_expression] [HAVING having_expression]; [ORDER BY column]; 8
  • 9. Using the ROLLUP Operator: Example SELECT department_id, job_id, SUM(salary) FROM hr.employees WHERE department_id < 60 GROUP BY ROLLUP(department_id, job_id); 1 2 3 Total by DEPARTMENT_ID and JOB_ID Total by DEPARTMENT_ID Grand total 9
  • 10. Using the CUBE Operator • CUBE is an extension of the GROUP BY clause • You can use the CUBE operator to produce cross-tabulation values with a single SELECT statement SELECT [column,] group_function(column)... FROM table [WHERE condition] [GROUP BY [CUBE] group_by_expression] [HAVING having_expression] [ORDER BY column]; 10
  • 11. 1 2 3 4 Grand total Total by JOB_ID Total by DEPARTMENT_ID and JOB_ID Total by DEPARTMENT_ID SELECT department_id, job_id, SUM(salary) FROM hr.employees WHERE department_id < 60 GROUP BY CUBE (department_id, job_id); . . . Using the CUBE Operator: Example 11
  • 12. GROUPING SETS • The GROUPING SETS syntax is used to define multiple groupings in the same query • All groupings specified in the GROUPING SETS clause are computed and the results of individual groupings are combined with a UNION ALL operation • Grouping set efficiency: • Only one pass over the base table is required • There is no need to write complex UNION statements • The more elements GROUPING SETS has, the greater the performance benefit 12
  • 13. SELECT department_id, job_id, manager_id, AVG(salary) FROM hr.employees GROUP BY GROUPING SETS ((department_id,job_id), (job_id,manager_id)); GROUPING SETS: Example . . . . . . 1 2 13
  • 14. Composite Columns • A composite column is a collection of columns that are treated as a unit. ROLLUP (a,(b,c), d) • Use parentheses within the GROUP BY clause to group columns, so that they are treated as a unit while computing ROLLUP or CUBE operators. • When used with ROLLUP or CUBE, composite columns require skipping aggregation across certain levels. 14
  • 15. SELECT department_id, job_id, manager_id, SUM(salary) FROM hr.employees GROUP BY ROLLUP( department_id,(job_id, manager_id)); Composite Columns: Example … 1 2 3 4 15
  • 17. Overview of SQL for Analysis and Reporting • Oracle has enhanced SQL's analytical processing capabilities by introducing a family of analytic SQL functions • These analytic functions enable you to calculate and perform: • Reporting operations • Rankings and percentiles • Moving window calculations • Inter-row calculations (LAG/LEAD, FIRST/LAST etc.) • Pivoting operations (11g) • Pattern matching (12c) • Linear regression and predictions 17
  • 18. Why Use Analytic Functions? • Ability to see one row from another row in the results • Avoid self-join queries • Summary data in detail rows • Slice and dice within the results • Performance improvement, in some cases 18
  • 19. Concepts Used in Analytic Functions • Result set partitions: These are created and available to any aggregate results such as sums and averages. The term “partitions” is unrelated to the table partitions feature. • Window: For each row in a partition, you can define a sliding window of data, which determines the range of rows used to perform the calculations for the current row. • Current row: Each calculation performed with an analytic function is based on a current row within a partition. It serves as the reference point determining the start and end of the window. 19
  • 20. Reporting Functions • We can use aggregative functions as analytic functions (i.e. SUM, AVG, MIN, MAX, COUNT etc.) • Each row will get the aggregative value for a given partition without the need for group by clause so we can have multiple group by’s on the same row • Getting the raw data along with the aggregated value • Use Order By to get cumulative aggrigations 20
  • 21. Report Functions 21 SELECT last_name, salary, department_id, ROUND(AVG(salary) OVER (PARTITION BY department_id),2) A, COUNT(*) OVER (PARTITION BY manager_id) B, SUM(salary) OVER (PARTITION BY department_id ORDER BY salary) C, MAX(salary) OVER () D FROM hr.employees;
  • 23. Using the Ranking Functions • A ranking function computes the rank of a record compared to other records in the data set based on the values of a set of measures. The types of ranking function are: • RANK and DENSE_RANK functions • ROW_NUMBER function • PERCENT_RANK function • NTILE function 23
  • 24. Working with the RANK Function • The RANK function calculates the rank of a value in a group of values, which is useful for top-N and bottom-N reporting. • When using the RANK function, ascending is the default sort order, which you can change to descending. • Rows with equal values for the ranking criteria receive the same rank. • Oracle Database then adds the number of tied rows to the tied rank to calculate the next rank. RANK ( ) OVER ( [query_partition_clause] order_by_clause ) 24
  • 25. Using the RANK Function: Example 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; 25
  • 26. RANK and DENSE_RANK Functions: Example 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 department_id, last_name, salary DESC, "Rank" DESC; DENSE_RANK ( ) OVER ([query_partition_clause] order_by_clause) 26
  • 27. Working with the ROW_NUMBER Function • The ROW_NUMBER function calculates a sequential number of a value in a group of values. • When using the ROW_NUMBER function, ascending is the default sort order, which you can change to descending. • Rows with equal values for the ranking criteria receive a different number. ROW_NUMBER ( ) OVER ( [query_partition_clause] order_by_clause ) 27
  • 28. ROW_NUMBER vs. ROWNUM • ROWNUM is a pseudo column, ROW_NUMBER is an actual function • It is calculated when the result returns to the client • ROWNUM requires sorting of the entire dataset in order to return an ordered list • ROW_NUMBER will only sort the required rows thus giving better performance 28
  • 29. Using the PERCENT_RANK Function • Uses rank values in its numerator and returns the percent rank of a value relative to a group of values • PERCENT_RANK of a row is calculated as follows: • The range of values returned by PERCENT_RANK is 0 to 1, inclusive. The first row in any set has a PERCENT_RANK of 0. The return value is NUMBER. Its syntax is: (rank of row in its partition - 1) / (number of rows in the partition - 1) PERCENT_RANK () OVER ([query_partition_clause] order_by_clause) 29
  • 30. Using the PERCENT_RANK Function: Example SELECT department_id, last_name, salary, PERCENT_RANK() OVER (PARTITION BY department_id ORDER BY salary DESC) AS pr FROM hr.employees ORDER BY department_id, pr, salary; . . . 30
  • 31. Working with the NTILE Function • Not really a rank function • Divides an ordered data set into a number of buckets indicated by expr and assigns the appropriate bucket number to each row • The buckets are numbered 1 through expr NTILE ( expr ) OVER ([query_partition_clause] order_by_clause) 31
  • 32. Summary of Ranking Functions • Different ranking functions may return different results if the data has ties SELECT last_name, salary, department_id, ROW_NUMBER() OVER (PARTITION BY department_id ORDER BY salary DESC) A, RANK() OVER (PARTITION BY department_id ORDER BY salary DESC) B, DENSE_RANK() OVER (PARTITION BY department_id ORDER BY salary DESC) C, PERCENT_RANK() OVER (PARTITION BY department_id ORDER BY salary DESC) D, NTILE(4) OVER (PARTITION BY department_id ORDER BY salary DESC) E FROM hr.employees; 32
  • 34. Using the LAG and LEAD Analytic Functions • LAG provides access to more than one row of a table at the same time without a self-join. • Given a series of rows returned from a query and a position of the cursor, LAG provides access to a row at a given physical offset before that position. • If you do not specify the offset, its default is 1. • If the offset goes beyond the scope of the window, the optional default value is returned. If you do not specify the default, its value is NULL. {LAG | LEAD}(value_expr [, offset ] [, default ]) OVER ([ query_partition_clause ] order_by_clause) 34
  • 35. Using the LAG and LEAD Analytic Functions: Example SELECT time_id, TO_CHAR(SUM(amount_sold),'9,999,999') AS SALES, TO_CHAR(LAG(SUM(amount_sold),1) OVER (ORDER BY time_id),'9,999,999') AS LAG1, TO_CHAR(LEAD(SUM(amount_sold),1) OVER (ORDER BY time_id),'9,999,999') AS LEAD1 FROM sales WHERE time_id >= TO_DATE('10-OCT-2000') AND time_id <= TO_DATE('14-OCT-2000') GROUP BY time_id; 35
  • 36. Using FIRST_VALUE/LAST_VALUE • Returns the first/last value in an ordered set of values • If the first value in the set is null, then the function returns NULL unless you specify IGNORE NULLS. This setting is useful for data densification. 38 FIRST_VALUE (expr [ IGNORE NULLS ]) OVER (analytic_clause) LAST_VALUE (expr [ IGNORE NULLS ]) OVER (analytic_clause)
  • 37. Using FIRST_VALUE Analytic Function Example SELECT department_id, last_name, salary, FIRST_VALUE(last_name) OVER (ORDER BY salary ASC ROWS UNBOUNDED PRECEDING) AS lowest_sal, LAST_VALUE(last_name) OVER (ORDER BY salary ASC ROWS BETWEEN UNBOUNDED PRECEDING and UNBOUNDED FOLLOWING) AS highest_sal FROM (SELECT * FROM employees WHERE department_id = 30 ORDER BY employee_id) ORDER BY department_id, last_name, salary; 39
  • 38. Using NTH_VALUE Analytic Function • Returns the N-th values in an ordered set of values • Different default window: RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW NTH_VALUE (measure_expr, n) [ FROM { FIRST | LAST } ][ { RESPECT | IGNORE } NULLS ] OVER (analytic_clause) 40
  • 39. Using NTH_VALUE Analytic Function Example SELECT prod_id, channel_id, MIN(amount_sold), NTH_VALUE ( MIN(amount_sold), 2) OVER (PARTITION BY prod_id ORDER BY channel_id ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) nv FROM sh.sales WHERE prod_id BETWEEN 13 and 16 GROUP BY prod_id, channel_id; 41
  • 40. Using the LISTAGG Function • For a specified measure, LISTAGG orders data within each group specified in the ORDER BY clause and then concatenates the values of the measure column • WARNING: Limited to output of 4000 chars (else, error message in runtime) 42 LISTAGG(measure_expr [, 'delimiter']) WITHIN GROUP (order_by_clause) [OVER query_partition_clause]
  • 41. Using the LISTAGG Function Example SELECT department_id "Dept", hire_date "Date", last_name "Name", LISTAGG(last_name, ', ') WITHIN GROUP (ORDER BY hire_date, last_name) OVER (PARTITION BY department_id) as "Emp_list" FROM hr.employees WHERE hire_date < '01-SEP-2003' ORDER BY "Dept", "Date", "Name"; 43
  • 43. Window Functions • The windowing_clause gives some analytic functions a further degree of control over this window within the current partition • The windowing_clause can only be used if an order_by_clause is present • The windows are always limited to the current partition • Generally, the default window is the entire work set unless said otherwise 45
  • 44. Windowing Clause Useful Usages • Cumulative aggregation • Sliding average over proceeding and/or following rows • Using the RANGE parameter to filter aggregation records 46
  • 45. Windows can be by RANGE or ROWS 47 Possible values for start_point and end_point UNBOUNDED PRECEDING The window starts at the first row of the partition. Only available for start points. UNBOUNDED FOLLOWING The window ends at the last row of the partition. Only available for end points. CURRENT ROW The window starts or ends at the current row value_expr PRECEDING A physical or logical offset before the current row. When used with RANGE, can also be an interval literal value_expr FOLLOWING As above, but an offset after the current row RANGE BETWEEN start_point AND end_point ROWS BETWEEN start_point AND end_point
  • 46. Shortcuts • Useful shortcuts for the windowing clause: 48 ROWS UNBOUNDED PRECEDING ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW ROWS 10 PRECEDING ROWS BETWEEN 10 PRECEDING AND CURRENT ROW ROWS CURRENT ROW ROWS BETWEEN CURRENT ROW AND CURRENT ROW (1 row)
  • 47. Oracle 12c New Feature Overview Just a couple, we can talk for hours on all the new features..  49
  • 48. What’s New in Oracle 12c • Top-N Queries and pagination: returning the top-n queries • syntactic honey – just a syntax enhancement, not performance enhancement • Pattern matching: New MATCH_RECOGNIZE syntax for finding row between patterns 50
  • 49. Top-N Examples 51 SELECT last_name, salary FROM hr.employees ORDER BY salary FETCH FIRST 4 ROWS ONLY; SELECT last_name, salary FROM hr.employees ORDER BY salary FETCH FIRST 4 ROWS WITH TIES; SELECT last_name, salary FROM hr.employees ORDER BY salary DESC FETCH FIRST 10 PERCENT ROWS ONLY;
  • 50. What is Pattern Matching? • A new syntax that allows us to identify and group rows with consecutive values • Consecutive in this regards – row after row • Uses regular expression like syntax to find patterns • Finds complex behavior we couldn’t found before, or needed PL/SQL for it 52
  • 51. Example: Pages in a Book Example • Our goal: find uninterrupted sequences in a book • This can be useful for detecting missing records or sequential behavior 53 (source: “Database 12c Row Pattern Matching” (OOW2014 session), by Stew Ashton).
  • 52. SELECT * FROM book_pages MATCH_RECOGNIZE ( ORDER BY page PATTERN (A B*) DEFINE B AS page = PREV(page)+1 ONE ROW PER MATCH MEASURES A.page firstpage, LAST(page) lastpage, COUNT(*) cnt AFTER MATCH SKIP PAST LAST ROW ); 1. Define input 2. Pattern Matching 3. Order input 4. Process pattern 5. Using defined conditions 6. Output: rows per match 7. Output: columns per row 8. Where to go after match? Pattern Matching Example SELECT * FROM book_pages MATCH_RECOGNIZE ( ORDER BY page MEASURES A.page firstpage, LAST(page) lastpage, COUNT(*) cnt ONE ROW PER MATCH AFTER MATCH SKIP PAST LAST ROW PATTERN (A B*) DEFINE B AS page = PREV(page)+1 );
  • 53. And the Result… 55 FIRSTPAGE LASTPAGE CNT ---------- ---------- ---------- 1 3 3 5 7 3 10 15 6 42 42 1
  • 55. Summary • We talked about advanced aggregation clauses, multi- dimensional aggregation, and how utilizing it can save us time and effort • Analytic functions are really important both for performance and for code clarity • We saw how rank function work and how to use windows • We explored some Oracle 12c enhancements – more information about that can be found in my blog: www.realdbamgic.com 57
  • 56. Thank You! Zohar Elkayam twitter: @realmgic Zohar@Brillix.co.il www.realdbamagic.com 58