Slides from presentation delivered to IOUG Collaborate, April 24, 2012, by Dan Stober. Topic: Understanding the Windowing Clause of Oracle Analytic SQL.
The document discusses analytic functions and the Cauchy-Riemann equations. It provides examples of determining whether functions are analytic or not based on satisfying the Cauchy-Riemann equations. It also discusses harmonic functions and their conjugate harmonic functions. Specifically, it defines analytic and harmonic functions, presents the Cauchy-Riemann equations and examples of applying them, discusses harmonic functions and provides examples of determining if functions are harmonic.
Applications of analytic functions and vector calculusPoojith Chowdhary
Analytic functions are functions that are locally defined by a convergent power series. They are used to compute cumulative, moving, centered, and reporting aggregates. Analytic functions are processed after joins, WHERE clauses, GROUP BY clauses, and HAVING clauses, and can only appear in the select list or ORDER BY clause. Common applications include calculating counts of employees under each manager.
Slides from OpenWorld 2013 presentation.
Analytics have been there since 8.1.6, but they are still dramatically underused by application developers. This session looks at the syntax and usage of analytic functions, and how they can supercharge your SQL skillset.
This document discusses cube, rollup and materialized views in Oracle databases. It provides an overview of how cube and rollup extend the GROUP BY clause to automatically calculate subtotals and totals. It also discusses how materialized views can store the results of a query to improve performance for frequent or complex queries. The document includes examples demonstrating how to use cube, rollup, and materialized views.
Analytic SQL functions, or "window functions have been there since 8.1.6, but they are still dramatically underused by application developers. This session looks at the syntax and usage of analytic functions, and how they can supercharge your SQL skillset.
Covers analytics from their inception in 8.1.6 all the through to enhancements in 18 and 19
This document discusses techniques for joining data from multiple database tables. It covers equijoins to retrieve matching records between tables, non-equijoins to retrieve records with non-equal conditions, outer joins to include non-matching records, and self joins to join a table to itself. Examples are provided to demonstrate how to write SQL statements to perform each type of join and include additional conditions.
This document discusses different types of joins that can be used to retrieve data from multiple database tables. It describes equijoins, non-equijoins, outer joins, and self joins. Key points include:
- Joins allow querying data from more than one table by specifying a join condition in the WHERE clause relating column values across tables.
- Equijoins use equality (=) conditions to join tables, while non-equijoins use between operators.
- Outer joins retrieve all rows from one or both tables, including those with no join match.
- Self joins match a table to itself to relate records via non-primary key columns, such as relating employees to their managers.
This document discusses how to restrict and sort data retrieved by SQL queries. It covers limiting rows using the WHERE clause and comparison operators, and sorting rows using the ORDER BY clause. Examples are provided for each clause and operator to filter rows by conditions and sort the output in ascending or descending order on one or multiple columns. Parentheses can be used to override the default order of operation precedence.
The document discusses analytic functions and the Cauchy-Riemann equations. It provides examples of determining whether functions are analytic or not based on satisfying the Cauchy-Riemann equations. It also discusses harmonic functions and their conjugate harmonic functions. Specifically, it defines analytic and harmonic functions, presents the Cauchy-Riemann equations and examples of applying them, discusses harmonic functions and provides examples of determining if functions are harmonic.
Applications of analytic functions and vector calculusPoojith Chowdhary
Analytic functions are functions that are locally defined by a convergent power series. They are used to compute cumulative, moving, centered, and reporting aggregates. Analytic functions are processed after joins, WHERE clauses, GROUP BY clauses, and HAVING clauses, and can only appear in the select list or ORDER BY clause. Common applications include calculating counts of employees under each manager.
Slides from OpenWorld 2013 presentation.
Analytics have been there since 8.1.6, but they are still dramatically underused by application developers. This session looks at the syntax and usage of analytic functions, and how they can supercharge your SQL skillset.
This document discusses cube, rollup and materialized views in Oracle databases. It provides an overview of how cube and rollup extend the GROUP BY clause to automatically calculate subtotals and totals. It also discusses how materialized views can store the results of a query to improve performance for frequent or complex queries. The document includes examples demonstrating how to use cube, rollup, and materialized views.
Analytic SQL functions, or "window functions have been there since 8.1.6, but they are still dramatically underused by application developers. This session looks at the syntax and usage of analytic functions, and how they can supercharge your SQL skillset.
Covers analytics from their inception in 8.1.6 all the through to enhancements in 18 and 19
This document discusses techniques for joining data from multiple database tables. It covers equijoins to retrieve matching records between tables, non-equijoins to retrieve records with non-equal conditions, outer joins to include non-matching records, and self joins to join a table to itself. Examples are provided to demonstrate how to write SQL statements to perform each type of join and include additional conditions.
This document discusses different types of joins that can be used to retrieve data from multiple database tables. It describes equijoins, non-equijoins, outer joins, and self joins. Key points include:
- Joins allow querying data from more than one table by specifying a join condition in the WHERE clause relating column values across tables.
- Equijoins use equality (=) conditions to join tables, while non-equijoins use between operators.
- Outer joins retrieve all rows from one or both tables, including those with no join match.
- Self joins match a table to itself to relate records via non-primary key columns, such as relating employees to their managers.
This document discusses how to restrict and sort data retrieved by SQL queries. It covers limiting rows using the WHERE clause and comparison operators, and sorting rows using the ORDER BY clause. Examples are provided for each clause and operator to filter rows by conditions and sort the output in ascending or descending order on one or multiple columns. Parentheses can be used to override the default order of operation precedence.
This document discusses restricting and sorting data in SQL queries. It describes how to limit rows returned using a WHERE clause and comparison operators. It also explains how to sort rows using an ORDER BY clause, including sorting in ascending and descending order and by multiple columns. Logical operators, precedence rules, and NULL handling are also covered.
This document contains examples of SQL queries being run on database tables to retrieve various data. The queries demonstrate selecting data from tables, filtering on conditions, using aggregation functions like COUNT and AVG, joining tables, and more. The tables being queried include EMP, DEPT, and other tables containing employee and department data.
This document discusses restricting and sorting data in SQL queries. It covers limiting rows using the WHERE clause with various operators like comparison, logical, BETWEEN, IN, LIKE and IS NULL. It also covers sorting result rows using the ORDER BY clause, including sorting in ascending and descending order and by multiple columns. The overall goal is to select specific data rows and control the order of rows displayed in the results.
Les05[1]Aggregating Data Using Group Functionssiavosh kaviani
This document discusses how to use group functions in SQL to aggregate data and group rows together. It describes the available group functions like COUNT, AVG, MAX, MIN, and SUM. It explains how to use the GROUP BY clause to divide rows into groups and the HAVING clause to filter groups. It also shows examples of grouping data by department to find average salaries and summing salaries by job and department.
The document discusses the use of Data Definition Language (DDL) to define and modify database tables through commands like CREATE TABLE, DROP TABLE, and ALTER TABLE. It describes different data types that can be used as table columns like VARCHAR, INTEGER, DATE, and constraints like PRIMARY KEY, FOREIGN KEY, and NOT NULL. DDL is used to specify the structure and schema of database tables and relationships between tables.
This document discusses how to limit and sort data retrieved from a database table using SQL queries. It covers using the WHERE clause to restrict rows by conditions, comparison operators like = and BETWEEN, logical operators like AND and OR, and the ORDER BY clause to sort rows in ascending or descending order based on one or more columns. Examples are provided for each technique.
Make your data dance: PIVOT, UNPIVOT & GROUP BY extensionsstewashton
This document discusses using UNPIVOT, PIVOT and GROUP BY extensions in SQL to transform and summarize data in various ways. Specifically, it shows how to:
1) Use UNPIVOT to transform columns into rows and PIVOT to transform rows into columns.
2) Use GROUP BY with ROLLUP, CUBE and GROUPING SETS functions to generate subtotals and totals across multiple levels or dimensions of data.
3) Apply techniques like UNPIVOT, PIVOT and GROUP BY to real-world sales data to transform it into a spreadsheet-like format with rows, columns, subtotals and totals.
This document contains a log of questions and answers related to SQL queries on sample tables. It includes 12 questions on topics like selecting data, filtering results, aggregation, joins and updates. The questions involve writing queries on tables for employees, departments, items and transactions to retrieve, calculate and update stored data.
This document discusses techniques for joining data from multiple database tables, including:
- Performing equijoins to retrieve matching records between tables based on equality conditions.
- Using outer joins to also return rows with no matches between tables.
- Self joins to join a table to itself based on relationships between records in the same table.
This document discusses how to aggregate data using group functions in SQL. It describes various group functions like AVG, COUNT, MAX, MIN, and SUM. It explains how to use the GROUP BY clause to group data by one or more columns and produce aggregate results for each group. It also covers using the HAVING clause to filter groups based on aggregate conditions.
The document discusses various SQL clauses and operators for restricting, sorting, and filtering data retrieved from database tables. It covers the WHERE clause for filtering rows, comparison operators like = and BETWEEN, logical operators like AND and OR, NULL handling, pattern matching with LIKE, and sorting order with ORDER BY. Examples are provided to demonstrate how each technique can be used in a SELECT statement to selectively retrieve only the needed data from database tables.
How information systems are built or acquired puts information, which is what they should be about, in a secondary place. Our language adapted accordingly, and we no longer talk about information systems but applications. Applications evolved in a way to break data into diverse fragments, tightly coupled with applications and expensive to integrate. The result is technical debt, which is re-paid by taking even bigger "loans", resulting in an ever-increasing technical debt. Software engineering and procurement practices work in sync with market forces to maintain this trend. This talk demonstrates how natural this situation is. The question is: can something be done to reverse the trend?
inQuba Webinar Mastering Customer Journey Management with Dr Graham HillLizaNolte
HERE IS YOUR WEBINAR CONTENT! 'Mastering Customer Journey Management with Dr. Graham Hill'. We hope you find the webinar recording both insightful and enjoyable.
In this webinar, we explored essential aspects of Customer Journey Management and personalization. Here’s a summary of the key insights and topics discussed:
Key Takeaways:
Understanding the Customer Journey: Dr. Hill emphasized the importance of mapping and understanding the complete customer journey to identify touchpoints and opportunities for improvement.
Personalization Strategies: We discussed how to leverage data and insights to create personalized experiences that resonate with customers.
Technology Integration: Insights were shared on how inQuba’s advanced technology can streamline customer interactions and drive operational efficiency.
Main news related to the CCS TSI 2023 (2023/1695)Jakub Marek
An English 🇬🇧 translation of a presentation to the speech I gave about the main changes brought by CCS TSI 2023 at the biggest Czech conference on Communications and signalling systems on Railways, which was held in Clarion Hotel Olomouc from 7th to 9th November 2023 (konferenceszt.cz). Attended by around 500 participants and 200 on-line followers.
The original Czech 🇨🇿 version of the presentation can be found here: https://www.slideshare.net/slideshow/hlavni-novinky-souvisejici-s-ccs-tsi-2023-2023-1695/269688092 .
The videorecording (in Czech) from the presentation is available here: https://youtu.be/WzjJWm4IyPk?si=SImb06tuXGb30BEH .
Dandelion Hashtable: beyond billion requests per second on a commodity serverAntonios Katsarakis
This slide deck presents DLHT, a concurrent in-memory hashtable. Despite efforts to optimize hashtables, that go as far as sacrificing core functionality, state-of-the-art designs still incur multiple memory accesses per request and block request processing in three cases. First, most hashtables block while waiting for data to be retrieved from memory. Second, open-addressing designs, which represent the current state-of-the-art, either cannot free index slots on deletes or must block all requests to do so. Third, index resizes block every request until all objects are copied to the new index. Defying folklore wisdom, DLHT forgoes open-addressing and adopts a fully-featured and memory-aware closed-addressing design based on bounded cache-line-chaining. This design offers lock-free index operations and deletes that free slots instantly, (2) completes most requests with a single memory access, (3) utilizes software prefetching to hide memory latencies, and (4) employs a novel non-blocking and parallel resizing. In a commodity server and a memory-resident workload, DLHT surpasses 1.6B requests per second and provides 3.5x (12x) the throughput of the state-of-the-art closed-addressing (open-addressing) resizable hashtable on Gets (Deletes).
For the full video of this presentation, please visit: https://www.edge-ai-vision.com/2024/06/temporal-event-neural-networks-a-more-efficient-alternative-to-the-transformer-a-presentation-from-brainchip/
Chris Jones, Director of Product Management at BrainChip , presents the “Temporal Event Neural Networks: A More Efficient Alternative to the Transformer” tutorial at the May 2024 Embedded Vision Summit.
The expansion of AI services necessitates enhanced computational capabilities on edge devices. Temporal Event Neural Networks (TENNs), developed by BrainChip, represent a novel and highly efficient state-space network. TENNs demonstrate exceptional proficiency in handling multi-dimensional streaming data, facilitating advancements in object detection, action recognition, speech enhancement and language model/sequence generation. Through the utilization of polynomial-based continuous convolutions, TENNs streamline models, expedite training processes and significantly diminish memory requirements, achieving notable reductions of up to 50x in parameters and 5,000x in energy consumption compared to prevailing methodologies like transformers.
Integration with BrainChip’s Akida neuromorphic hardware IP further enhances TENNs’ capabilities, enabling the realization of highly capable, portable and passively cooled edge devices. This presentation delves into the technical innovations underlying TENNs, presents real-world benchmarks, and elucidates how this cutting-edge approach is positioned to revolutionize edge AI across diverse applications.
This document discusses restricting and sorting data in SQL queries. It describes how to limit rows returned using a WHERE clause and comparison operators. It also explains how to sort rows using an ORDER BY clause, including sorting in ascending and descending order and by multiple columns. Logical operators, precedence rules, and NULL handling are also covered.
This document contains examples of SQL queries being run on database tables to retrieve various data. The queries demonstrate selecting data from tables, filtering on conditions, using aggregation functions like COUNT and AVG, joining tables, and more. The tables being queried include EMP, DEPT, and other tables containing employee and department data.
This document discusses restricting and sorting data in SQL queries. It covers limiting rows using the WHERE clause with various operators like comparison, logical, BETWEEN, IN, LIKE and IS NULL. It also covers sorting result rows using the ORDER BY clause, including sorting in ascending and descending order and by multiple columns. The overall goal is to select specific data rows and control the order of rows displayed in the results.
Les05[1]Aggregating Data Using Group Functionssiavosh kaviani
This document discusses how to use group functions in SQL to aggregate data and group rows together. It describes the available group functions like COUNT, AVG, MAX, MIN, and SUM. It explains how to use the GROUP BY clause to divide rows into groups and the HAVING clause to filter groups. It also shows examples of grouping data by department to find average salaries and summing salaries by job and department.
The document discusses the use of Data Definition Language (DDL) to define and modify database tables through commands like CREATE TABLE, DROP TABLE, and ALTER TABLE. It describes different data types that can be used as table columns like VARCHAR, INTEGER, DATE, and constraints like PRIMARY KEY, FOREIGN KEY, and NOT NULL. DDL is used to specify the structure and schema of database tables and relationships between tables.
This document discusses how to limit and sort data retrieved from a database table using SQL queries. It covers using the WHERE clause to restrict rows by conditions, comparison operators like = and BETWEEN, logical operators like AND and OR, and the ORDER BY clause to sort rows in ascending or descending order based on one or more columns. Examples are provided for each technique.
Make your data dance: PIVOT, UNPIVOT & GROUP BY extensionsstewashton
This document discusses using UNPIVOT, PIVOT and GROUP BY extensions in SQL to transform and summarize data in various ways. Specifically, it shows how to:
1) Use UNPIVOT to transform columns into rows and PIVOT to transform rows into columns.
2) Use GROUP BY with ROLLUP, CUBE and GROUPING SETS functions to generate subtotals and totals across multiple levels or dimensions of data.
3) Apply techniques like UNPIVOT, PIVOT and GROUP BY to real-world sales data to transform it into a spreadsheet-like format with rows, columns, subtotals and totals.
This document contains a log of questions and answers related to SQL queries on sample tables. It includes 12 questions on topics like selecting data, filtering results, aggregation, joins and updates. The questions involve writing queries on tables for employees, departments, items and transactions to retrieve, calculate and update stored data.
This document discusses techniques for joining data from multiple database tables, including:
- Performing equijoins to retrieve matching records between tables based on equality conditions.
- Using outer joins to also return rows with no matches between tables.
- Self joins to join a table to itself based on relationships between records in the same table.
This document discusses how to aggregate data using group functions in SQL. It describes various group functions like AVG, COUNT, MAX, MIN, and SUM. It explains how to use the GROUP BY clause to group data by one or more columns and produce aggregate results for each group. It also covers using the HAVING clause to filter groups based on aggregate conditions.
The document discusses various SQL clauses and operators for restricting, sorting, and filtering data retrieved from database tables. It covers the WHERE clause for filtering rows, comparison operators like = and BETWEEN, logical operators like AND and OR, NULL handling, pattern matching with LIKE, and sorting order with ORDER BY. Examples are provided to demonstrate how each technique can be used in a SELECT statement to selectively retrieve only the needed data from database tables.
How information systems are built or acquired puts information, which is what they should be about, in a secondary place. Our language adapted accordingly, and we no longer talk about information systems but applications. Applications evolved in a way to break data into diverse fragments, tightly coupled with applications and expensive to integrate. The result is technical debt, which is re-paid by taking even bigger "loans", resulting in an ever-increasing technical debt. Software engineering and procurement practices work in sync with market forces to maintain this trend. This talk demonstrates how natural this situation is. The question is: can something be done to reverse the trend?
inQuba Webinar Mastering Customer Journey Management with Dr Graham HillLizaNolte
HERE IS YOUR WEBINAR CONTENT! 'Mastering Customer Journey Management with Dr. Graham Hill'. We hope you find the webinar recording both insightful and enjoyable.
In this webinar, we explored essential aspects of Customer Journey Management and personalization. Here’s a summary of the key insights and topics discussed:
Key Takeaways:
Understanding the Customer Journey: Dr. Hill emphasized the importance of mapping and understanding the complete customer journey to identify touchpoints and opportunities for improvement.
Personalization Strategies: We discussed how to leverage data and insights to create personalized experiences that resonate with customers.
Technology Integration: Insights were shared on how inQuba’s advanced technology can streamline customer interactions and drive operational efficiency.
Main news related to the CCS TSI 2023 (2023/1695)Jakub Marek
An English 🇬🇧 translation of a presentation to the speech I gave about the main changes brought by CCS TSI 2023 at the biggest Czech conference on Communications and signalling systems on Railways, which was held in Clarion Hotel Olomouc from 7th to 9th November 2023 (konferenceszt.cz). Attended by around 500 participants and 200 on-line followers.
The original Czech 🇨🇿 version of the presentation can be found here: https://www.slideshare.net/slideshow/hlavni-novinky-souvisejici-s-ccs-tsi-2023-2023-1695/269688092 .
The videorecording (in Czech) from the presentation is available here: https://youtu.be/WzjJWm4IyPk?si=SImb06tuXGb30BEH .
Dandelion Hashtable: beyond billion requests per second on a commodity serverAntonios Katsarakis
This slide deck presents DLHT, a concurrent in-memory hashtable. Despite efforts to optimize hashtables, that go as far as sacrificing core functionality, state-of-the-art designs still incur multiple memory accesses per request and block request processing in three cases. First, most hashtables block while waiting for data to be retrieved from memory. Second, open-addressing designs, which represent the current state-of-the-art, either cannot free index slots on deletes or must block all requests to do so. Third, index resizes block every request until all objects are copied to the new index. Defying folklore wisdom, DLHT forgoes open-addressing and adopts a fully-featured and memory-aware closed-addressing design based on bounded cache-line-chaining. This design offers lock-free index operations and deletes that free slots instantly, (2) completes most requests with a single memory access, (3) utilizes software prefetching to hide memory latencies, and (4) employs a novel non-blocking and parallel resizing. In a commodity server and a memory-resident workload, DLHT surpasses 1.6B requests per second and provides 3.5x (12x) the throughput of the state-of-the-art closed-addressing (open-addressing) resizable hashtable on Gets (Deletes).
For the full video of this presentation, please visit: https://www.edge-ai-vision.com/2024/06/temporal-event-neural-networks-a-more-efficient-alternative-to-the-transformer-a-presentation-from-brainchip/
Chris Jones, Director of Product Management at BrainChip , presents the “Temporal Event Neural Networks: A More Efficient Alternative to the Transformer” tutorial at the May 2024 Embedded Vision Summit.
The expansion of AI services necessitates enhanced computational capabilities on edge devices. Temporal Event Neural Networks (TENNs), developed by BrainChip, represent a novel and highly efficient state-space network. TENNs demonstrate exceptional proficiency in handling multi-dimensional streaming data, facilitating advancements in object detection, action recognition, speech enhancement and language model/sequence generation. Through the utilization of polynomial-based continuous convolutions, TENNs streamline models, expedite training processes and significantly diminish memory requirements, achieving notable reductions of up to 50x in parameters and 5,000x in energy consumption compared to prevailing methodologies like transformers.
Integration with BrainChip’s Akida neuromorphic hardware IP further enhances TENNs’ capabilities, enabling the realization of highly capable, portable and passively cooled edge devices. This presentation delves into the technical innovations underlying TENNs, presents real-world benchmarks, and elucidates how this cutting-edge approach is positioned to revolutionize edge AI across diverse applications.
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-EfficiencyScyllaDB
Freshworks creates AI-boosted business software that helps employees work more efficiently and effectively. Managing data across multiple RDBMS and NoSQL databases was already a challenge at their current scale. To prepare for 10X growth, they knew it was time to rethink their database strategy. Learn how they architected a solution that would simplify scaling while keeping costs under control.
"Frontline Battles with DDoS: Best practices and Lessons Learned", Igor IvaniukFwdays
At this talk we will discuss DDoS protection tools and best practices, discuss network architectures and what AWS has to offer. Also, we will look into one of the largest DDoS attacks on Ukrainian infrastructure that happened in February 2022. We'll see, what techniques helped to keep the web resources available for Ukrainians and how AWS improved DDoS protection for all customers based on Ukraine experience
Northern Engraving | Nameplate Manufacturing Process - 2024Northern Engraving
Manufacturing custom quality metal nameplates and badges involves several standard operations. Processes include sheet prep, lithography, screening, coating, punch press and inspection. All decoration is completed in the flat sheet with adhesive and tooling operations following. The possibilities for creating unique durable nameplates are endless. How will you create your brand identity? We can help!
What is an RPA CoE? Session 1 – CoE VisionDianaGray10
In the first session, we will review the organization's vision and how this has an impact on the COE Structure.
Topics covered:
• The role of a steering committee
• How do the organization’s priorities determine CoE Structure?
Speaker:
Chris Bolin, Senior Intelligent Automation Architect Anika Systems
Session 1 - Intro to Robotic Process Automation.pdfUiPathCommunity
👉 Check out our full 'Africa Series - Automation Student Developers (EN)' page to register for the full program:
https://bit.ly/Automation_Student_Kickstart
In this session, we shall introduce you to the world of automation, the UiPath Platform, and guide you on how to install and setup UiPath Studio on your Windows PC.
📕 Detailed agenda:
What is RPA? Benefits of RPA?
RPA Applications
The UiPath End-to-End Automation Platform
UiPath Studio CE Installation and Setup
💻 Extra training through UiPath Academy:
Introduction to Automation
UiPath Business Automation Platform
Explore automation development with UiPath Studio
👉 Register here for our upcoming Session 2 on June 20: Introduction to UiPath Studio Fundamentals: https://community.uipath.com/events/details/uipath-lagos-presents-session-2-introduction-to-uipath-studio-fundamentals/
The Microsoft 365 Migration Tutorial For Beginner.pptxoperationspcvita
This presentation will help you understand the power of Microsoft 365. However, we have mentioned every productivity app included in Office 365. Additionally, we have suggested the migration situation related to Office 365 and how we can help you.
You can also read: https://www.systoolsgroup.com/updates/office-365-tenant-to-tenant-migration-step-by-step-complete-guide/
This talk will cover ScyllaDB Architecture from the cluster-level view and zoom in on data distribution and internal node architecture. In the process, we will learn the secret sauce used to get ScyllaDB's high availability and superior performance. We will also touch on the upcoming changes to ScyllaDB architecture, moving to strongly consistent metadata and tablets.
AppSec PNW: Android and iOS Application Security with MobSFAjin Abraham
Mobile Security Framework - MobSF is a free and open source automated mobile application security testing environment designed to help security engineers, researchers, developers, and penetration testers to identify security vulnerabilities, malicious behaviours and privacy concerns in mobile applications using static and dynamic analysis. It supports all the popular mobile application binaries and source code formats built for Android and iOS devices. In addition to automated security assessment, it also offers an interactive testing environment to build and execute scenario based test/fuzz cases against the application.
This talk covers:
Using MobSF for static analysis of mobile applications.
Interactive dynamic security assessment of Android and iOS applications.
Solving Mobile app CTF challenges.
Reverse engineering and runtime analysis of Mobile malware.
How to shift left and integrate MobSF/mobsfscan SAST and DAST in your build pipeline.
2. Dan Stober
• Data Architect – Intermountain Healthcare
• Attended California State Univ., Fresno
• Working in Oracle databases since 2001
• Frequent presenter at local and national user group conferences
• Oracle Open World - twice
• Private Instructor for Trutek
• Teaching PLSQL
• Oracle Certified SQL Expert
• Board of Trustees – Utah Oracle Users Group (UTOUG)
• Edit newsletter
• Write SQL Tip column
3. Dan Stober – Personal Stuff
• Married for twenty years with two kids
• Run two marathons
• Next one in four weeks
• Three Ragnars
• Enjoy
• Photography
• Travel
4. Intermountain Healthcare
• 23 hospitals in Utah and Idaho
• Non-profit integrated health care system
• 750 Employed physicians
• 32,000 employees
• The largest non-government employer in Utah
• One of the largest and most complete clinical data warehouses in the
world!
5. Session Norms
• Questions?
• Interrupt Me!
• I learn something from every session I do!
• Set the record straight!
• Cell phones?
• OK!
6. Shameless Plug
• UTOUG Fall Symposium
• Thursday, September 6
• Salt Lake City
• Call For Presentations is open!
• Deadline: June 15
• All things Oracle: DBA, Development, APEX, EBS, Business
Intelligence
7. Agenda
• Aggregate vs Analytic
• PARTITION BY
• ORDER BY
• Window Clause
•ROWS
•RANGE
8. 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
9. AGGREGATE OR ANALYTIC?
Which one are each of these? Aggregate Analytic
Analytic
COUNT
SUM
MAX
MIN
•What’s the difference?
SYNTAX OUTPUT
Aggregate (traditional) Query often includes the Output is a single row
keywords GROUP BY (or one row per group with GROUP BY)
Analytic OVER ( some other stuff) Does not change number of rows
10. AGGREGATE
EXAMPLES Deptno Ename Sal
SELECT COUNT ( * )
10 Clark 2450
FROM scott.emp;
COUNT(*) 10 King 5000
---------- 10 Miller 1300
14 SELECT COUNT ( * )
, SUM ( sal ) 20 Adams 1100
1 row selected. , MAX ( sal )
20 Ford 3000
, MIN ( ename )
FROM scott.emp; 20 Jones 2975
SELECT SUM ( sal ) COUNT(*) SUM(SAL) MAX(SAL) MIN(ENAME) 20 Scott 3000
FROM scott.emp; ---------- ---------- ---------- ----------
14 29025 5000 ADAMS 20 Smith 800
SUM(SAL)
---------- 30 Allen 1600
29025 1 row selected.
30 Blake 2850
1 row selected. 30 James 950
30 Martin 1250
30 Turner 1500
30 Ward 1250
11. AGGREGATE
SELECT COUNT ( * )
EXAMPLES Deptno Ename Sal
, SUM ( sal )
10 Clark 2450
FROM scott.emp SELECT deptno
WHERE deptno = 30; , COUNT ( * ) 10 King 5000
, SUM ( sal )
COUNT(*) SUM(SAL) 10 Miller 1300
FROM scott.emp
---------- ----------
GROUP BY deptno; 20 Adams 1100
6 9400
DEPTNO COUNT(*) SUM(SAL) 20 Ford 3000
1 row selected. ---------- ---------- ----------
20 Jones 2975
10 3 8750
20 5 10875 20 Scott 3000
SELECT deptno 30 6 9400
, COUNT ( * ) 20 Smith 800
, SUM ( sal ) 3 rows selected. 30 Allen 1600
FROM scott.emp;
One record for 30 Blake 2850
*
ERROR at line 1: each group 30 James 950
ORA-00937: not a single-group group function 30 Martin 1250
30 Turner 1500
30 Ward 1250
12. ANALYTIC
FUNCTIONS
DEPTNO ENAME SAL COUNT(*)OVER() SUM(SAL)OVER()
What makes a function ------- ---------- ------- -------------- --------------
analytic? 10 CLARK 2450 14 29025
10 KING 5000 14 29025
• Keyword OVER 10 MILLER 1300 14 29025
• Followed by set of 20
20
ADAMS
FORD
1100
3000
14
14
29025
29025
parentheses 20 JONES 2975 14 29025
20 SCOTT 3000 14 29025
SELECT deptno, ename, sal 20 SMITH 800 14 29025
30 ALLEN 1600 14 29025
, COUNT ( * ) OVER ()
30 BLAKE 2850 14 29025
, SUM ( sal ) OVER () 30 JAMES 950 14 29025
FROM scott.emp; 30 MARTIN 1250 14 29025
30 TURNER 1500 14 29025
30 WARD 1250 14 29025
14 rows selected. Returns one result
for each record in the dataset.
No grouping
13. ANALYTIC
FUNCTIONS Deptno Ename Sal
With WHERE Clause… 10 Clark 2450
•Which happens first? 10 King 5000
SELECT deptno, ename, sal Even with 10 Miller 1300
, COUNT ( * ) OVER () OVER() and empty parens, the
function operates only on the 20 Adams 1100
, SUM ( sal ) OVER ()
FROM scott.emp records which meet the conditions 20 Ford 3000
WHERE deptno = 30; of the WHERE clause 20 Jones 2975
DEPTNO ENAME SAL COUNT(*)OVER() SUM(SAL)OVER() 20 Scott 3000
------- ---------- ------- -------------- -------------- 20 Smith 800
30 ALLEN 1600 6 9450
30 BLAKE 2850 6 9450 30 Allen 1600
30 JAMES 950 6 9450 30 Blake 2850
30 MARTIN 1250 6 9450
30 TURNER 1500 6 9450 30 James 950
30 WARD 1250 6 9450 30 Martin 1250
6 rows selected. 30 Turner 1500
30 Ward 1250
14. DISTINCT vs
GROUP BY
When analytic
functions are
Is there a
YES
involved: difference?
SELECT deptno SELECT DISTINCT deptno
, COUNT(*) OVER ( ) AS empcnt , COUNT(*) OVER ( ) AS empcnt
FROM scott.emp FROM scott.emp;
GROUP BY deptno;
DEPTNO EMPCNT
DEPTNO EMPCNT ---------- ---------- 1. Table Joins
---------- ---------- 10 14
10 3 20 14
2. WHERE clause filters
20 3 30 14 3. GROUP BY
30 3
3 rows selected.
4. Analytic Functions
3 rows selected. 5. DISTINCT
6. Ordering
16. THE ANALYTIC
CLAUSE
• Within the set of parentheses
• Expressions telling the function to calculate differently
• Three possible components
• Partition
• Order
• Windowing
• Some or all are optional, depending upon the function
• Components must be in this order
17. PARTITION BY
SELECT deptno, ename, sal, job
, COUNT ( * ) OVER ( PARTITION BY job ) jobcount
, SUM ( sal ) OVER ( PARTITION BY deptno ) deptsum
FROM scott.emp;
Analytic function
DEPTNO ENAME SAL JOB JOBCOUNT DEPTSUM
calculated on a subset of ------- -------- ------- --------- ---------- ----------
10 CLARK 2450 MANAGER 3 8750
the records 10 KING 5000 PRESIDENT 1 8750
10 MILLER 1300 CLERK 4 8750
20 ADAMS 1100 CLERK 4 10875
20 FORD 3000 ANALYST 2 10875
20 JONES 2975 MANAGER 3 10875
Can differ for each one 20 SCOTT 3000 ANALYST 2 10875
20 SMITH 800 CLERK 4 10875
30 ALLEN 1600 SALESMAN 4 9400
30 BLAKE 2850 MANAGER 3 9400
30 JAMES 950 CLERK 4 9400
30 MARTIN 1250 SALESMAN 4 9400
30 TURNER 1500 SALESMAN 4 9400
30 WARD 1250 SALESMAN 4 9400
14 rows selected.
18. HERE’S THE
SAME QUERY
SELECT deptno, ename, sal, job
,( SELECT COUNT ( * ) FROM scott.emp WHERE job = e.job ) jobcount
Using aggregate ,( SELECT SUM ( sal ) FROM scott.emp WHERE deptno = e.deptno ) deptsum
FROM scott.emp e;
functions in the DEPTNO ENAME SAL JOB JOBCOUNT DEPTSUM
traditional manner ------- -------- ------- --------- ---------- ----------
10 CLARK 2450 MANAGER 3 8750
10 KING 5000 PRESIDENT 1 8750
10 MILLER 1300 CLERK 4 8750
Correlated 20 ADAMS 1100 CLERK 4 10875
scalar 20 FORD 3000 ANALYST 2 10875
20 JONES 2975 MANAGER 3 10875
subqueries 20 SCOTT 3000 ANALYST 2 10875
20 SMITH 800 CLERK 4 10875
30 ALLEN 1600 SALESMAN 4 9400
Same Results as 30 BLAKE 2850 MANAGER 3 9400
30 JAMES 950 CLERK 4 9400
prior slide 30 MARTIN 1250 SALESMAN 4 9400
30 TURNER 1500 SALESMAN 4 9400
30 WARD 1250 SALESMAN 4 9400
14 rows selected.
20. TWO NEW
FUNCTIONS
• LAG
• LEAD
• Usage:
• LAG ( field_name, num_recs ) OVER ( )
• Return the value from a field when looking one record (or more)
behind/ahead
• Using the order specified
• ORDER BY is required
• Does not have to be order used in the query
• Optional second param to look more than one record
• These functions are analytic only
21. LAG
DEMONSTRATION ENAME HIREDATE
SELECT deptno, ename, hiredate
, LAG ( ename ) OVER ( ORDER BY hiredate ) prior_hire ADAMS 1/12/1983
FROM scott.emp
ORDER BY deptno, ename; 2 ALLEN 2/20/1981
DEPTNO ENAME HIREDATE PRIOR_HIRE BLAKE 5/1/1981
---------- ---------- --------- ----------
10 CLARK 09-JUN-81 BLAKE CLARK 6/9/1981
10 KING 17-NOV-81 MARTIN FORD 12/3/1981
10 MILLER 23-JAN-82 FORD
20 ADAMS 23-MAY-87 SCOTT JAMES 12/3/1981
20 FORD 03-DEC-81 JAMES JONES 4/02/1981
20 JONES 02-APR-81 WARD
KING 11/17/1981
20 SCOTT 09-DEC-82 MILLER
20 SMITH 17-DEC-80 MARTIN 9/28/1981
30 ALLEN 20-FEB-81 SMITH
MILLER 1/23/1982
30 BLAKE 01-MAY-81 JONES
30 JAMES 03-DEC-81 KING SCOTT 12/9/1982
30 MARTIN 28-SEP-81 TURNER
30 TURNER 08-SEP-81 CLARK 1 SMITH 12/17/1980
30 WARD 22-FEB-81 ALLEN TURNER 9/08/1981
14 rows selected. 3 WARD 2/22/1981
22. ORDER BY
VARIATION
SELECT deptno, ename, sal ENAME
, LAG ( ename ) OVER ( ORDER BY ename ) f1
ADAMS
, LAG ( ename , 2 ) OVER ( ORDER BY ename ) f2
, LEAD ( ename ) OVER ( ORDER BY ename DESC) f3 ALLEN
, LAG ( sal ) OVER ( ORDER BY ename ) f4
BLAKE
FROM scott.emp
ORDER BY deptno, ename; CLARK
DEPTNO ENAME SAL F1 F2 F3 F4
---------- ---------- ---------- ---------- ---------- ---------- ---------- FORD
10 CLARK 2450 BLAKE ALLEN BLAKE 2850
JAMES
10 KING 5000 JONES JAMES JONES 2975
10 MILLER 1300 MARTIN KING MARTIN 1250 JONES
20 ADAMS 1100
20 FORD 3000 CLARK BLAKE CLARK 2450 KING
20 JONES 2975 JAMES FORD JAMES 950
20 SCOTT 3000 MILLER MARTIN MILLER 1300 MARTIN
20 SMITH 800 SCOTT MILLER SCOTT 3000
30 ALLEN 1600 ADAMS ADAMS 1100 MILLER
30 BLAKE 2850 ALLEN ADAMS ALLEN 1600
30 JAMES 950 FORD CLARK FORD 3000 SCOTT
30 MARTIN 1250 KING JONES KING 5000 SMITH
30 TURNER 1500 SMITH SCOTT SMITH 800
30 WARD 1250 TURNER SMITH TURNER 1500 TURNER
14 rows selected. WARD
23. ORDER BY WITH
PARTITION BY Deptno Ename Sal
SELECT deptno, ename, sal
, LAG ( ename ) OVER ( ORDER BY ename ) f1 10 Clark 2450
, LAG ( ename ) OVER ( PARTITION BY deptno ORDER BY ename ) f2 10 King 5000
, LAG ( ename ) OVER ( PARTITION BY deptno ORDER BY sal DESC) f3
FROM scott.emp 10 Miller 1300
ORDER BY deptno, ename; 20 Adams 1100
DEPTNO ENAME SAL F1 F2 F3
20 Ford 3000
-------- ---------- -------- ---------- ---------- -------
10 CLARK 2450 BLAKE KING 20 Jones 2975
10 KING 5000 JONES CLARK
10 MILLER 1300 MARTIN KING CLARK 20 Scott 3000
20 ADAMS 1100 JONES
20 FORD 3000 CLARK ADAMS SCOTT 20 Smith 800
20 JONES 2975 JAMES FORD FORD
30 Allen 1600
20 SCOTT 3000 MILLER JONES
20 SMITH 800 SCOTT SCOTT ADAMS 30 Blake 2850
30 ALLEN 1600 ADAMS BLAKE
30 BLAKE 2850 ALLEN ALLEN 30 James 950
30 JAMES 950 FORD BLAKE WARD
30 MARTIN 1250 KING JAMES TURNER 30 Martin 1250
30 TURNER 1500 SMITH MARTIN ALLEN
30 Turner 1500
30 WARD 1250 TURNER TURNER MARTIN
30 Ward 1250
14 rows selected.
24. ORDER OF ITEMS IN
ANALYTIC CLAUSE
SELECT deptno, empno, ename, sal
, MIN ( sal ) OVER ( ORDER BY ename PARTITION BY deptno ) minsal
FROM scott.emp; Components
, MIN ( sal ) OVER ( ORDER BY ename PARTITION BY deptno ) minsal
* must be in
ERROR at line 2:
ORA-00907: missing right parenthesis correct order
ORA-00907 missing right parenthesis
Cause: A left parenthesis has been entered without a closing right
parenthesis, or extra information was contained in the parentheses. All
parentheses must be entered in pairs.
Action: Correct the syntax and retry the statement.
25. THREE MORE
NEW FUNCTIONS
• Ordering ( Ranking ) functions:
• RANK
• DENSE_RANK
• ROW_NUMBER
• Usage:
• RANK ( ) OVER ( ORDER BY field_name )
• Where does this record fall, when the records are placed in
a certain order?
• Does not have to be order used in the query
• All three functions return a number
• Difference between functions is how they handle ties
• These functions are analytic only
26. RANKING
FUNCTIONS
SELECT deptno, ename, sal
, RANK ( ) OVER ( ORDER BY ename ) f1
, DENSE_RANK ( ) OVER ( ORDER BY ename ) f2 When there are
, ROW_NUMBER ( ) OVER ( ORDER BY ename ) f3
FROM scott.emp
no ties, all three
ORDER BY deptno, sal; of these
DEPTNO ENAME SAL F1 F2 F3
---------- ---------- ---------- ---------- ---------- ----------
functions return
10 MILLER
10 CLARK
1300
2450
10
4
10
4
10
4
the same
10 KING
20 SMITH
5000
800
8
12 12
8 8
12
values.
20 ADAMS 1100 1 1 1
20 JONES 2975 7 7 7
20 FORD 3000 5 5 5
20 SCOTT 3000 11 11 11
30 JAMES 950 6 6 6
30 WARD 1250 14 14 14
30 MARTIN 1250 9 9 9
30 TURNER 1500 13 13 13
30 ALLEN 1600 2 2 2
30 BLAKE 2850 3 3 3
14 rows selected.
27. RANKING FUNCTIONS
WITH TIES
SELECT deptno, ename, sal
, RANK ( ) OVER ( ORDER BY sal ) f1
, DENSE_RANK ( ) OVER ( ORDER BY sal ) f2
, ROW_NUMBER ( ) OVER ( ORDER BY sal ) f3
RANK and DENSE_RANK
FROM scott.emp will assign the same
ORDER BY deptno, sal; number to multiple records
DEPTNO ENAME SAL F1 F2 F3 with the same sort value
---------- ---------- ---------- ---------- ---------- ----------
10 MILLER 1300 6 5 6
10 CLARK 2450 9 8 9 The difference is in how
10 KING 5000 14 12 14
20 SMITH 800 1 1 1 each one handles the
20 ADAMS 1100 3 3 3 record which follows
20 JONES 2975 11 10 11
20 FORD 3000 12 11 13
20 SCOTT 3000 12 11 12 ROW_NUMBER assigns a
30 JAMES 950 2 2 2
30 WARD 1250 4 4 4
unique number to each
30 MARTIN 1250 4 4 5 record. The highest value
30 TURNER 1500 7 6 7
30 ALLEN 1600 8 7 8 assigned by
30 BLAKE 2850 10 9 10 ROW_NUMBER will be
14 rows selected. equal to COUNT(*)
28. ORDER BY There is no assurance the
CAVEAT #1 row_number() assignments
would not be different for the
SELECT deptno, ename, job, sal, hiredate
, ROW_NUMBER ( ) OVER ( ORDER BY sal DESC) r1 $3000 sal on the next time
, ROW_NUMBER ( ) OVER ( PARTITION BY job ORDER BY sal ) r2 the query is executed
FROM scott.emp;
DEPTNO ENAME JOB SAL HIREDATE R1 R2
---------- ---------- --------- ---------- --------- ---------- ----------
10 CLARK MANAGER 2450 09-JUN-81 6 1
10 KING PRESIDENT 5000 17-NOV-81 1 1
10 MILLER CLERK 1300 23-JAN-82 9 4
20 ADAMS CLERK 1100 23-MAY-87 12 3
20 FORD ANALYST 3000 03-DEC-81 2 1
20 JONES MANAGER 2975 02-APR-81 4 3
20 SCOTT ANALYST 3000 19-APR-87 3 2
20 SMITH CLERK 800 17-DEC-80 14 1
30 ALLEN SALESMAN 1600 20-FEB-81 7 4
30 BLAKE MANAGER 2850 01-MAY-81 5 2
30 JAMES CLERK 950 03-DEC-81 13 2
30 MARTIN SALESMAN 1250 28-SEP-81 10 1
30 TURNER SALESMAN 1500 08-SEP-81 8 3
30 WARD SALESMAN 1250 22-FEB-81 11 2
14 rows selected.
29. ORDER BY
CAVEAT #2
• On many functions, using ORDER BY changes window
• SUM, COUNT, MAX, MIN, LAST_VALUE
SELECT deptno, ename, sal
, SUM ( sal ) OVER ( ORDER BY ename ) s On each record, results are
, COUNT ( * ) OVER ( ORDER BY ename ) c
, MIN ( sal ) OVER ( ORDER BY ename ) mn from the beginning of the
, MAX ( sal ) OVER ( ORDER BY ename ) mx partition to the current record,
FROM scott.emp as defined by the ORDER BY
WHERE deptno = 10;
DEPTNO ENAME SAL S C MN MX
---------- ---------- ---------- ---------- ---------- ---------- ----------
10 CLARK 2450 2450 1 2450 2450
10 KING 5000 7450 2 2450 5000
10 MILLER 1300 8750 3 1300 5000
3 rows selected.
30. WHY?
This is the default behavior.
If you include an ORDER BY where one would not be necessary, Oracle
assumes it is there for a reason.
1 + 3 + 5 = 9 and 5 + 1 + 3 = 9
Very powerful for running calculations, such as MTD:
Week Number Sales Month To Date
1 11,000 11,000
2 15,000 26,000 SUM ( sales ) OVER
3 12,000 38,000 (ORDER BY week_number)
4 16,000 54,000
31. DEFAULT
WINDOWING
... OVER ( PARTITION BY cust )
Cust Order_Date COUNT ( * )
A 12/25/2010
Calculation on each of OVER ...
A 1/15/2011
these records includes all COUNT
A 2/28/2011 three of these records 3
B 6/16/2010 3
B 9/15/2010 Calculation on each of 3
B 1/1/2011 these records includes all 4
B 2/12/2011
four of these records 4
4
4
32. DEFAULT
WINDOWING
... OVER OVER ( PARTITION BY cust
... ( PARTITION BY cust )
ORDER BY order_date )
Cust Order_Date
Calculation on each of
COUNT ( * )
A 12/25/2010 these records includes only OVER ...
A 1/15/2011 the records which COUNT COUNT
A 2/28/2011 preceded it in the partition 3 1
B 6/16/2010 3
Calculation on each of 2
B 9/15/2010
these records includes only 3 3
B 1/1/2011
the records which 4
1
B 2/12/2011 preceded it in the partition 4
2
4
3
4
4
33. WINDOWING
• Demonstration of default windowing
• With and without ORDER BY SUM 1 is the same as SUM3
SELECT deptno, ename, sal
, SUM ( sal ) OVER ( ) sum1 SUM 2 is the same as SUM4
, SUM ( sal ) OVER ( ORDER BY ename ) sum2
, SUM ( sal ) OVER ( ORDER BY ename
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) sum3 Default
, SUM ( sal ) OVER ( ORDER BY ename
ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW ) sum4
windowing
FROM scott.emp saves a lot
WHERE deptno = 10;
of typing
DEPTNO ENAME SAL SUM1 SUM2 SUM3 SUM4
---------- ---------- ---------- ---------- ---------- ---------- ---------- and
10 CLARK 2450 8750 2450 8750 2450 eliminates
10 KING 5000 8750 7450 8750 7450
10 MILLER 1300 8750 8750 8750 8750 clutter
3 rows selected.
34. WINDOWING
SELECT deptno, ename, sal
, SUM ( sal ) OVER ( ORDER BY ename • Selects a smaller subset than the
ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING ) sum1 partition
, SUM ( sal ) OVER (
ROWS BETWEEN 1
PARTITION BY deptno ORDER BY ename
PRECEDING AND 1 FOLLOWING ) sum2
• Based on a number of records
before/after
FROM scott.emp;
DEPTNO ENAME SAL SUM1 SUM2 • Or a time period before/after
---------- ---------- ---------- ---------- ----------
10 CLARK 2450 8300 7450 2450+5000
10 KING 5000 9225 8750
10 MILLER 1300 5550 6300
20 ADAMS 1100 2700 4100 2450+5000+1300
20 FORD 3000 6400 7075
20 JONES 2975 8925 8975 5000+1300
20 SCOTT 3000 5100 6775
20 SMITH 800 5300 3800
30 ALLEN 1600 5550 4450
1100+3000
30 BLAKE 2850 6900 5400
30 JAMES 950 6925 5050 1100+3000+2975
30 MARTIN 1250 7550 3700
30 TURNER 1500 3550 4000
30 WARD 1250 2750 2750
14 rows selected.
36. WINDOWING CLAUSE
COMPARISON
Row windowing:
Restricts window by records Analytic function will
Based on ORDER BY include the 10 records
just before this record
ROWS BETWEEN 10 PRECEDING and the 10 records
after
AND 10 FOLLOWING
Analytic function will
Range windowing: include all records
Restricts window by a period of time or a value within 10 days of the
References field used in ORDER BY record in question
RANGE BETWEEN INTERVAL '10' DAY PRECEDING
AND INTERVAL '10' DAY FOLLOWING
37. RANGE
WINDOWING RANGE
SELECT ename, sal
not ROWS
, COUNT(*) OVER ( ORDER BY sal RANGE BETWEEN 200 PRECEDING
AND 200 FOLLOWING ) emps_200_sal
FROM scott.emp;
Consider only
ENAME SAL EMPS_200_SAL those records
---------- ---------- ------------
SMITH 800 2 within $200 of the
JAMES 950 3 value from the
ADAMS 1100 5
WARD 1250 4 current record
MARTIN 1250 4
MILLER 1300 5
TURNER 1500 3
Which field?
ALLEN 1600 2 SAL: The field
CLARK 2450 1
BLAKE 2850 4 that is used in
JONES 2975 4 the ORDER BY
SCOTT 3000 4
FORD 3000 4
KING 5000 1
14 rows selected.
38. WITH AN
INTERVAL
SELECT empno, ename, hiredate
, COUNT(*) OVER ( ORDER BY hiredate
RANGE BETWEEN INTERVAL '1 3' DAY TO HOUR FOLLOWING
AND INTERVAL '1-6' YEAR TO MONTH FOLLOWING ) AS example
FROM scott.emp;
• This is just an extreme example:
• Window includes people hired from
•
One day and three hours after the current record, to
•
One year and six months after the current record
• The real point on display here …
• How do you use intervals?
39. ASIDE
• Designating an Interval
• An Interval is a period of time
• Between two dates or two timestamps
INTERVAL '10' DAY
1. Why is the number enclosed in single quotes?
2. Why is the unit singular?
• “DAY” instead of “DAYS”?
40. DESIGNATING
AN INTERVAL
INTERVAL '3' DAY Number of Units is a varchar string
(enclosed in single quotes)
Number of Unit Number of units can include values for more than
Keyword Type(s) one unit type
Units
Multiple units: specify first and last, separated by
INTERVAL '7' HOUR keyword “TO”
INTERVAL '7:45' HOUR TO MINUTE Think of these units
designations as akin
INTERVAL '7:45' MINUTE TO SECOND to a format mask
used with TO_DATE.
INTERVAL '7:45:00' HOUR TO SECOND You are specifying the
significance of the
INTERVAL '3 7:45:00' DAY TO SECOND numbers. Note that
you include only the
INTERVAL '3 7:45' DAY TO MINUTE first and last units.
Varchar
41. DESIGNATING
AN INTERVAL
SELECT INTERVAL '3' DAY AS interv_1
, INTERVAL '3 00:00:00' DAY TO SECOND AS interv_2
•
, INTERVAL '72' HOUR AS interv_3
These Interval fields MINUTE
, INTERVAL '4320' are equivalent: AS interv_4
FROM dual;
INTERV_1 INTERV_2 INTERV_3 INTERV_4
----------------- --------------------- ----------------- -------------------
+03 00:00:00 +03 00:00:00.000000 +03 00:00:00 +03 00:00:00
1 row selected.
All of these express
the interval three days
42. INTERVAL ERROR
ORA-00923: FROM keyword not found where expected
• This is a generic error, raised in many situations
• But, one possibility with Intervals is…
INTERVAL 3 DAY
Results in ORA-00923 Solution INTERVAL '3' DAY
43. INTERVAL ERROR
ORA-30089: missing or invalid <datetime field>
INTERVAL '03-04-05' YEAR TO DAY
You cannot specify an interval than
Results in ORA-30089 Solution spans between months and days.
The two valid ranges for interval units
are:
YEAR >> MONTH
DAYS >> SECOND
44. INTERVAL ERROR
ORA-01867: the interval is invalid
• Don’t you love unhelpful error messages?
INTERVAL '03:04:05' HOUR TO MINUTE
The unit specification
Results in ORA-01867 Solution does not match the
literal
INTERVAL '03:04:05' HOUR TO SECOND
45. INTERVAL ERROR
ORA-01873: the leading precision of the interval is too small
• Meaning: value specified exceeds the default precision specification
for the interval component
• Solution, specify a higher precision
INTERVAL '300' DAY
Results in ORA-01873 Solution INTERVAL '300' DAY(3)
Unit Component Default Precision
DAY 2
HOUR 3
MINUTE 5
SECOND 7
46. RANGE EXAMPLE
SELECT empno, ename, hiredate
, COUNT(*) OVER ( ORDER BY hiredate
How many people were
RANGE BETWEEN INTERVAL '6' MONTH PRECEDING hired within six months
AND INTERVAL '6' MONTH FOLLOWING ) AS six_mo
, COUNT(*) OVER ( ORDER BY hiredate
of this person?
RANGE BETWEEN CURRENT ROW
AND INTERVAL '6' MONTH FOLLOWING ) AS six_mo_after
FROM scott.emp;
EMPNO ENAME HIREDATE SIX_MO SIX_MO_AFTER
How many people were
---------- ---------- --------- ---------- ------------ hired six months after
7369 SMITH 17-DEC-80 6 6
7499 ALLEN 20-FEB-81 6 5 this person?
7521 WARD 22-FEB-81 6 4
7566 JONES 02-APR-81 8 5
7698 BLAKE 01-MAY-81 8 4
7782 CLARK 09-JUN-81 11 6
7844 TURNER 08-SEP-81 9 6
7654 MARTIN 28-SEP-81 9 5
7839 KING 17-NOV-81 7 4
7900 JAMES 03-DEC-81 7 3
7902 FORD 03-DEC-81 7 3
7934 MILLER 23-JAN-82 6 1
7788 SCOTT 09-DEC-82 2 2
7876 ADAMS 12-JAN-83 2 1
14 rows selected.
47. THREE LEVELS
OF CONDITIONS
SELECT ename, job, sal
, COUNT(*) OVER ( PARTITION BY job
ORDER BY sal
RANGE BETWEEN 200 PRECEDING
AND 200 FOLLOWING ) emps_200_sal
FROM scott.emp
WHERE ename < 'M'
ORDER BY deptno, empno; 1) WHERE ename < 'M'
ENAME JOB SAL EMPS_200_SAL
---------- --------- ---------- ------------
2) PARTITION BY job
CLARK
KING
MANAGER
PRESIDENT
2450
5000
1
1
3) RANGE BETWEEN …
JONES MANAGER 2975 2
ADAMS CLERK 1100 2
FORD ANALYST 3000 1
ALLEN SALESMAN 1600 1
BLAKE MANAGER 2850 2
JAMES CLERK 950 2
8 rows selected.
48. ANOTHER RANGE
LIMITATION
• Only one sort key allowed when windowing with RANGE
• Because range depends on the ORDER BY to derive the field
SELECT ename, sal
, COUNT(*) OVER ( ORDER BY sal, comm
RANGE BETWEEN 200 PRECEDING
AND 200 FOLLOWING ) emps_200_sal
FROM scott.emp;
, COUNT(*) OVER ( ORDER BY sal, comm What the error message means: You cannot
* specify two sort fields with a RANGE window
ERROR at line 2:
ORA-30486: invalid window aggregation group in the window specification
EXCEPT… RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
in two (common)
clauses: RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING
49. RANGE EXAMPLE
SELECT empno, ename, hiredate
, LAG (ename) OVER ( ORDER BY hiredate
RANGE BETWEEN CURRENT ROW
AND INTERVAL '6' MONTH FOLLOWING ) AS nexthire
FROM scott.emp; EMPNO ENAME HIREDATE
---------- ---------- ---------
7369 SMITH 17-DEC-80
RANGE BETWEEN CURRENT ROW 7499 ALLEN 20-FEB-81
* 7521 WARD 22-FEB-81
7566 JONES 02-APR-81
ERROR at line 3: 7698 BLAKE 01-MAY-81
ORA-00907: missing right parenthesis 7782 CLARK 09-JUN-81
7844 TURNER 08-SEP-81
7654 MARTIN 28-SEP-81
What happened? 7839 KING 17-NOV-81
You cannot use LAG or LEAD with a RANGE window 7900 JAMES 03-DEC-81
7902 FORD 03-DEC-81
7934 MILLER 23-JAN-82
WHY? 7788 SCOTT 09-DEC-82
7876 ADAMS 12-JAN-83
A range sort does not specify individual records.
Consider the two records with the same hiredate 14 rows selected.
50. EXAMPLE
Show date of next order for customer
customer_id order_date Order_total Next Next
Order_Date order_amt
• Do we need a PARTITION BY?
103 3/29/1997 310.00 9/01/1998 13550.00
• If so, which field(s)?
103 9/01/1998 13550.00 9/13/1999 78.00
103 9/13/1999 78.00 10/02/1999 6653.40
• Do we need an ORDER BY?
103 10/02/1999 6653.40
• If yes, which field(s)?
105 3/20/1999 1926.60 8/31/1999 22150.00
105 8/31/1999 22150.10 1/08/2000 7826.00
• How will this be windowed?
105 1/08/2000 7826.00 1/26/2000 29473.80
• RANGE or ROWS?
105 1/26/2000 29473.80
51. NEXT ORDER
customer_id order_date Order_total Next Next
Order_Date order_amt
103 3/29/1997 310.00 9/01/1998 13550.00
103 9/01/1998 13550.00 9/13/1999 78.00
103 9/13/1999 78.00 10/02/1999 6653.40
103 10/02/1999 6653.40
105 3/20/1999 1926.60 8/31/1999 22150.00
105 8/31/1999 22150.10 1/08/2000 7826.00
105 1/08/2000 7826.00 1/26/2000 29473.80
105 1/26/2000 29473.80
• Here are five ways:
• LEAD
Show date of • LAG with reverse order
• MAX with ROWS current to 1 following
next order • MIN with ROWS 1 to unbounded following
• MIN or MAX with window only on 1 row following
52. DATE OF
NEXT ORDER
SELECT customer_id
, TRUNC ( order_date ) AS order_date
, order_total
, LEAD ( TRUNC ( order_date ) ) OVER
( PARTITION BY customer_id ORDER BY order_date ) AS next_order_date
FROM oe.orders
WHERE customer_id IN (103, 105) LAG ( TRUNC ( order_date ) ) OVER ( PARTITION BY customer_id
ORDER BY 1, 2; ORDER BY order_date DESC )
CUSTOMER_ID ORDER_DAT ORDER_TOTAL NEXT_ORDE
MAX ( TRUNC ( order_date ) ) OVER ( PARTITION BY customer_id
----------- --------- ----------- ---------
ORDER BY order_date
103 29-MAR-97 310 01-SEP-98 ROWS BETWEEN CURRENT ROW AND 1 FOLLOWING )
103 01-SEP-98 13550 13-SEP-99
103 13-SEP-99 78 02-OCT-99 MIN ( TRUNC ( order_date ) ) OVER ( PARTITION BY customer_id
103 02-OCT-99 6653.4 ORDER BY order_date
105 20-MAR-99 1926.6 31-AUG-99 ROWS BETWEEN 1 FOLLOWING AND UNBOUNDED FOLLOWING )
105 31-AUG-99 22150.1 08-JAN-00
105 08-JAN-00 7826 26-JAN-00 MIN ( TRUNC ( order_date ) ) OVER ( PARTITION BY customer_id
105 26-JAN-00 29473.8 ORDER BY order_date
ROWS BETWEEN 1 FOLLOWING AND 1 FOLLOWING )
8 rows selected.
53. AMOUNT OF
NEXT ORDER
SELECT customer_id
, TRUNC ( order_date ) AS order_date
, order_total
, LEAD ( order_total ) OVER ( PARTITION BY customer_id
ORDER BY order_date ) AS next_order_total
FROM oe.orders
WHERE customer_id IN (103, 105) LAG ( order_total ) OVER ( PARTITION BY customer_id
ORDER BY 1, 2; ORDER BY order_date DESC)
CUSTOMER_ID ORDER_DAT ORDER_TOTAL NEXT_ORDER_TOTAL
----------- --------- ----------- ----------------
103 29-MAR-97 310 13550
103 01-SEP-98 13550 78
103 13-SEP-99 78 6653.4
103 02-OCT-99 6653.4
105 20-MAR-99 1926.6 22150.1
105 31-AUG-99 22150.1 7826
105 08-JAN-00 7826 29473.8
105 26-JAN-00 29473.8
MAX ( order_total ) OVER ( PARTITION BY customer_id
8 rows selected.
ORDER BY order_date
ROWS BETWEEN 1 FOLLOWING AND 1 FOLLOWING )
54. WHY SO MANY?
SELECT customer_id
, TRUNC ( order_date ) AS order_date
, order_total
, LEAD ( order_total ) OVER
( PARTITION BY customer_id ORDER BY order_date ) AS next_order
, order_total + LEAD ( order_total ) OVER
( PARTITION BY customer_id ORDER BY order_date ) AS this_plus_next
, SUM ( order_total ) OVER
Using LEAD results in
( PARTITION BY customer_id ORDER BY order_date NULL at edge of
ROWS BETWEEN CURRENT ROW AND 1 FOLLOWING ) AS sum_this_next
FROM oe.orders
partition.
WHERE customer_id IN (103, 105)
ORDER BY 1, 2;
CUSTOMER_ID ORDER_DAT ORDER_TOTAL NEXT_ORDER THIS_PLUS_NEXT SUM_THIS_NEXT
----------- --------- ----------- ---------- -------------- -------------
Using SUM and
103 29-MAR-97 310 13550 13860 13860 windowing, avoids
103 01-SEP-98 13550 78 13628 13628
103 13-SEP-99 78 6653.4 6731.4 6731.4
nulls.
103 02-OCT-99 6653.4 6653.4
105 20-MAR-99 1926.6 22150.1 24076.7 24076.7
105 31-AUG-99 22150.1 7826 29976.1 29976.1
105 08-JAN-00 7826 29473.8 37299.8 37299.8
105 26-JAN-00 29473.8 29473.8
8 rows selected.
56. Shortcut
• If…
• You omit BETWEEN and AND
• And the windowing value is <= CURRENT ROW
• Then…
• The second argument is assumed to be CURRENT ROW
ROWS UNBOUNDED PRECEDING ROWS BETWEEN UNBOUNDED PRECEDING
= AND CURRENT ROW
ROWS BETWEEN 10 PRECEDING
ROWS 10 PRECEDING =
AND CURRENT ROW
ROWS BETWEEN CURRENT ROW
ROWS CURRENT ROW =
AND CURRENT ROW
57. SHORTCUT ERROR
SELECT ename, sal
, COUNT(*) OVER ( ORDER BY sal ROWS UNBOUNDED FOLLOWING)
FROM scott.emp;
, COUNT(*) OVER ( ORDER BY sal ROWS UNBOUNDED FOLLOWING)
*
ERROR at line 2:
ORA-00905: missing keyword
Upon encountering ORA-00905, you must correct syntax
because there is a missing keyword.
58. Recap
• Aggregate vs Analytic
• PARTITION BY
• ORDER BY
• Window Clause
• ROWS
• RANGE
59. THANK-YOU!
This is session #740
DAN STOBER
Questions? Comments?
dan.stober@utoug.org
Twitter: @dstober
Slides available on slideshare.net