SlideShare una empresa de Scribd logo
1 de 8
+
Window Aggregate
Functions
Dr. Silvio Sangineto
Business Analyst
E-Mail: s.sangineto@gmail.com
Web-Site: www.silviosangineto.it
+
Introduction
 Window aggregate functions are the same as the group
aggregate functions (for example, SUM, COUNT, AVG, MIN,
and MAX), except window aggregate functions are applied to a
window of rows defined by the OVER clause;
 Benefit: windower queries do not hide the detail. A row for
every row;
 Using the OVER clause you define a set of rows for the
function to work with per each underlying row.
+
Example 1
Select
custid,
orderid,
val,
SUM(val) OVER(PARTITION BY
custid) AS custtotal,
SUM(val) OVER() AS grandtotal
From
Sales.OrderValues;
 Results
+
Example 1
 Description
 Here’s an example of a query against the Sales.OrderValues view
returning for each order the customer ID, order ID, and order value;
using window functions, the query also returns the grand total of all
values and the customer total.
 Two differences: the grand total is of course the same for all rows
(we are using over with empty parentheses) . The customer total is
the same for all rows with the same customer ID
+
Framing
 Window aggregate functions support another filtering option
called framing.
 Idea: you define ordering within the partition by using a window
order clause, and then based on that order, you can confine a
frame of rows between two delimiters. You define the delimiters
by using a window frame clause.
 Requirement: a window order clause to be present because a
set has no order, and without order, limiting rows between two
delimiters would have no meaning
+
Framing
 You have to define frame units (rows or range) and the
delimiters.
 With the ROWS window frame unit, you can indicate the
delimiters as one of three options:
 UNBOUNDED PRECEDING or FOLLOWING, meaning the
beginning or end of the partition, respectively
 CURRENT ROW, obviously representing the current row
 ROWS PRECEDING or FOLLOWING, meaning n rows before or
after the current, respectively
+
Example 2
Select
custid,
orderid,
orderdate,
val,
SUM(val) OVER(PARTITION BY
custid ORDER BY orderdate, orderid
ROWS BETWEEN UNBOUNDED
PRECEDING AND CURRENT ROW)
AS runningtotal
From
Sales.OrderValues;
 Results
+
Example 2
 Description
 Observe how the values keep accumulating from the beginning of
the customer partition until the current row;
 Because window functions are supposed to operate on the
underlying query’s result set, they are allowed only in the SELECT
and ORDER BY clauses;
 If you need to refer to the result of a window function in any clause
that is evaluated before the SELECT clause, you need to use
a table expression.

Más contenido relacionado

Destacado

Studying Chemistry at the University of Bath
Studying Chemistry at the University of BathStudying Chemistry at the University of Bath
Studying Chemistry at the University of BathTeam MyRSC
 
Jan/Feb 2013 Devil's Corner Newsletter
Jan/Feb 2013 Devil's Corner NewsletterJan/Feb 2013 Devil's Corner Newsletter
Jan/Feb 2013 Devil's Corner NewsletterNoel Waterman
 
June 2012 1ID Fort Riley Monthly News Update
June 2012 1ID Fort Riley Monthly News Update June 2012 1ID Fort Riley Monthly News Update
June 2012 1ID Fort Riley Monthly News Update Noel Waterman
 
Nuostabus josephine wall piesiniai
Nuostabus josephine wall piesiniaiNuostabus josephine wall piesiniai
Nuostabus josephine wall piesiniaizigius
 
Soap anniversaries as media events
Soap anniversaries as media eventsSoap anniversaries as media events
Soap anniversaries as media eventsRuth Deller
 
31 July 2012 1HBCT Weekly News Update
31 July 2012 1HBCT Weekly News Update31 July 2012 1HBCT Weekly News Update
31 July 2012 1HBCT Weekly News UpdateNoel Waterman
 
God bless britain
God bless britainGod bless britain
God bless britainRuth Deller
 
黑客终极语言——Lisp
黑客终极语言——Lisp黑客终极语言——Lisp
黑客终极语言——LispRui Peng
 
Living W And Wo Unions
Living W And Wo UnionsLiving W And Wo Unions
Living W And Wo Unionsmadamseane
 

Destacado (19)

Studying Chemistry at the University of Bath
Studying Chemistry at the University of BathStudying Chemistry at the University of Bath
Studying Chemistry at the University of Bath
 
Jan/Feb 2013 Devil's Corner Newsletter
Jan/Feb 2013 Devil's Corner NewsletterJan/Feb 2013 Devil's Corner Newsletter
Jan/Feb 2013 Devil's Corner Newsletter
 
Kursus ict bt
Kursus ict btKursus ict bt
Kursus ict bt
 
June 2012 1ID Fort Riley Monthly News Update
June 2012 1ID Fort Riley Monthly News Update June 2012 1ID Fort Riley Monthly News Update
June 2012 1ID Fort Riley Monthly News Update
 
Nuostabus josephine wall piesiniai
Nuostabus josephine wall piesiniaiNuostabus josephine wall piesiniai
Nuostabus josephine wall piesiniai
 
bladder cancer
bladder cancerbladder cancer
bladder cancer
 
Bbcaudiences
BbcaudiencesBbcaudiences
Bbcaudiences
 
Data center sper sys
Data center sper sysData center sper sys
Data center sper sys
 
Evaluation 2
Evaluation 2Evaluation 2
Evaluation 2
 
ASER 2010
ASER 2010ASER 2010
ASER 2010
 
Highlyeffectiveschoollibraryprogram
HighlyeffectiveschoollibraryprogramHighlyeffectiveschoollibraryprogram
Highlyeffectiveschoollibraryprogram
 
Toy
ToyToy
Toy
 
Soap anniversaries as media events
Soap anniversaries as media eventsSoap anniversaries as media events
Soap anniversaries as media events
 
31 July 2012 1HBCT Weekly News Update
31 July 2012 1HBCT Weekly News Update31 July 2012 1HBCT Weekly News Update
31 July 2012 1HBCT Weekly News Update
 
God bless britain
God bless britainGod bless britain
God bless britain
 
黑客终极语言——Lisp
黑客终极语言——Lisp黑客终极语言——Lisp
黑客终极语言——Lisp
 
Bhsec q cto y2 night 2014
Bhsec q cto y2 night 2014 Bhsec q cto y2 night 2014
Bhsec q cto y2 night 2014
 
Sociology group
Sociology groupSociology group
Sociology group
 
Living W And Wo Unions
Living W And Wo UnionsLiving W And Wo Unions
Living W And Wo Unions
 

Similar a Window aggregate functions

Oracle_Analytical_function.pdf
Oracle_Analytical_function.pdfOracle_Analytical_function.pdf
Oracle_Analytical_function.pdfKalyankumarVenkat1
 
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
 
5.Analytical Function.pdf
5.Analytical Function.pdf5.Analytical Function.pdf
5.Analytical Function.pdfssuser8b6c85
 
Crosstab query techniques
Crosstab query techniquesCrosstab query techniques
Crosstab query techniquesaabaap
 
System verilog coverage
System verilog coverageSystem verilog coverage
System verilog coveragePushpa Yakkala
 
Analytic & Windowing functions in oracle
Analytic & Windowing functions in oracleAnalytic & Windowing functions in oracle
Analytic & Windowing functions in oracleLogan Palanisamy
 
procedures and arrays
procedures and arraysprocedures and arrays
procedures and arraysDivyaR219113
 
VISUAL BASIC 6 - CONTROLS AND DECLARATIONS
VISUAL BASIC 6 - CONTROLS AND DECLARATIONSVISUAL BASIC 6 - CONTROLS AND DECLARATIONS
VISUAL BASIC 6 - CONTROLS AND DECLARATIONSSuraj Kumar
 
SQL WORKSHOP::Lecture 7
SQL WORKSHOP::Lecture 7SQL WORKSHOP::Lecture 7
SQL WORKSHOP::Lecture 7Umair Amjad
 
Enabling Applications with Informix' new OLAP functionality
 Enabling Applications with Informix' new OLAP functionality Enabling Applications with Informix' new OLAP functionality
Enabling Applications with Informix' new OLAP functionalityAjay Gupte
 
Oracle Advanced SQL and Analytic Functions
Oracle Advanced SQL and Analytic FunctionsOracle Advanced SQL and Analytic Functions
Oracle Advanced SQL and Analytic FunctionsZohar Elkayam
 
Exploring Microoptimizations Using Tizen Code as an Example
Exploring Microoptimizations Using Tizen Code as an ExampleExploring Microoptimizations Using Tizen Code as an Example
Exploring Microoptimizations Using Tizen Code as an ExamplePVS-Studio
 
OBIEE 12c Advanced Analytic Functions
OBIEE 12c Advanced Analytic FunctionsOBIEE 12c Advanced Analytic Functions
OBIEE 12c Advanced Analytic FunctionsMichael Perhats
 
MSc COMPUTER APPLICATION
MSc COMPUTER APPLICATIONMSc COMPUTER APPLICATION
MSc COMPUTER APPLICATIONMugdhaSharma11
 

Similar a Window aggregate functions (20)

Oracle_Analytical_function.pdf
Oracle_Analytical_function.pdfOracle_Analytical_function.pdf
Oracle_Analytical_function.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
 
5.Analytical Function.pdf
5.Analytical Function.pdf5.Analytical Function.pdf
5.Analytical Function.pdf
 
Sql wksht-3
Sql wksht-3Sql wksht-3
Sql wksht-3
 
Crosstab query techniques
Crosstab query techniquesCrosstab query techniques
Crosstab query techniques
 
System verilog coverage
System verilog coverageSystem verilog coverage
System verilog coverage
 
Analytic & Windowing functions in oracle
Analytic & Windowing functions in oracleAnalytic & Windowing functions in oracle
Analytic & Windowing functions in oracle
 
procedures and arrays
procedures and arraysprocedures and arrays
procedures and arrays
 
Oracle SQL Advanced
Oracle SQL AdvancedOracle SQL Advanced
Oracle SQL Advanced
 
VISUAL BASIC 6 - CONTROLS AND DECLARATIONS
VISUAL BASIC 6 - CONTROLS AND DECLARATIONSVISUAL BASIC 6 - CONTROLS AND DECLARATIONS
VISUAL BASIC 6 - CONTROLS AND DECLARATIONS
 
SQL WORKSHOP::Lecture 7
SQL WORKSHOP::Lecture 7SQL WORKSHOP::Lecture 7
SQL WORKSHOP::Lecture 7
 
Enabling Applications with Informix' new OLAP functionality
 Enabling Applications with Informix' new OLAP functionality Enabling Applications with Informix' new OLAP functionality
Enabling Applications with Informix' new OLAP functionality
 
Oracle Advanced SQL and Analytic Functions
Oracle Advanced SQL and Analytic FunctionsOracle Advanced SQL and Analytic Functions
Oracle Advanced SQL and Analytic Functions
 
Sql ch 5
Sql ch 5Sql ch 5
Sql ch 5
 
Exploring Microoptimizations Using Tizen Code as an Example
Exploring Microoptimizations Using Tizen Code as an ExampleExploring Microoptimizations Using Tizen Code as an Example
Exploring Microoptimizations Using Tizen Code as an Example
 
OBIEE 12c Advanced Analytic Functions
OBIEE 12c Advanced Analytic FunctionsOBIEE 12c Advanced Analytic Functions
OBIEE 12c Advanced Analytic Functions
 
SQL Windowing
SQL WindowingSQL Windowing
SQL Windowing
 
MSc COMPUTER APPLICATION
MSc COMPUTER APPLICATIONMSc COMPUTER APPLICATION
MSc COMPUTER APPLICATION
 
Oracle General Ledger GL FSG
Oracle General Ledger GL FSG Oracle General Ledger GL FSG
Oracle General Ledger GL FSG
 
Sql
SqlSql
Sql
 

Último

MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...apidays
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamUiPathCommunity
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Victor Rentea
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
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
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 

Último (20)

MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
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
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 

Window aggregate functions

  • 1. + Window Aggregate Functions Dr. Silvio Sangineto Business Analyst E-Mail: s.sangineto@gmail.com Web-Site: www.silviosangineto.it
  • 2. + Introduction  Window aggregate functions are the same as the group aggregate functions (for example, SUM, COUNT, AVG, MIN, and MAX), except window aggregate functions are applied to a window of rows defined by the OVER clause;  Benefit: windower queries do not hide the detail. A row for every row;  Using the OVER clause you define a set of rows for the function to work with per each underlying row.
  • 3. + Example 1 Select custid, orderid, val, SUM(val) OVER(PARTITION BY custid) AS custtotal, SUM(val) OVER() AS grandtotal From Sales.OrderValues;  Results
  • 4. + Example 1  Description  Here’s an example of a query against the Sales.OrderValues view returning for each order the customer ID, order ID, and order value; using window functions, the query also returns the grand total of all values and the customer total.  Two differences: the grand total is of course the same for all rows (we are using over with empty parentheses) . The customer total is the same for all rows with the same customer ID
  • 5. + Framing  Window aggregate functions support another filtering option called framing.  Idea: you define ordering within the partition by using a window order clause, and then based on that order, you can confine a frame of rows between two delimiters. You define the delimiters by using a window frame clause.  Requirement: a window order clause to be present because a set has no order, and without order, limiting rows between two delimiters would have no meaning
  • 6. + Framing  You have to define frame units (rows or range) and the delimiters.  With the ROWS window frame unit, you can indicate the delimiters as one of three options:  UNBOUNDED PRECEDING or FOLLOWING, meaning the beginning or end of the partition, respectively  CURRENT ROW, obviously representing the current row  ROWS PRECEDING or FOLLOWING, meaning n rows before or after the current, respectively
  • 7. + Example 2 Select custid, orderid, orderdate, val, SUM(val) OVER(PARTITION BY custid ORDER BY orderdate, orderid ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS runningtotal From Sales.OrderValues;  Results
  • 8. + Example 2  Description  Observe how the values keep accumulating from the beginning of the customer partition until the current row;  Because window functions are supposed to operate on the underlying query’s result set, they are allowed only in the SELECT and ORDER BY clauses;  If you need to refer to the result of a window function in any clause that is evaluated before the SELECT clause, you need to use a table expression.