Sum Window Group Function:
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
SUM
window function: This SUM window group
function permits an aggregate to be computed across the defined group.
Groups are defined using the PARTITION BY clause. If PARTITION BY is not used then all rows are considered as a one group.
SELECT EMPLOYEEID,DEPARTMENTNO,SALARY,SUM(SALARY)
OVER (
ORDER BY
DEPARTMENTNO)
FROM EMPLOYEE2;
As
PARTITION is not specified all rows will be considered as a part of same
group.
Note that column title is GROUP SUM indicates the group function. We can also write the same query as follows:
SELECT EMPLOYEEID,DEPARTMENTNO,SALARY,
SUM(SALARY) OVER (
ORDER BY
DEPARTMENTNO ROWS BETWEEN UNBOUNDED PRECEDING
AND UNBOUNDED
FOLLOWING)
FROM EMPLOYEE2;
This means the words 'ROWS BETWEEN UNBOUNDED
PRECEDING AND UNBOUNDED FOLLOWING' are default for ordered analytical
functions.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
SUM WINDOW group Function with PARTITION:
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
We use PARTITION BY clause to perform grouping. Following query provides partitioning based on department.
SELECT
EMPLOYEEID,
DEPARTMENTNO,
SALARY,
SUM(SALARY) OVER (PARTITION BY DEPARTMENTNO ORDER BY
DEPARTMENTNO )
FROM EMPLOYEE2;
We
can get similar result using the following syntax:
SELECT
EMPLOYEEID,
DEPARTMENTNO,
SALARY,
SUM(SALARY) OVER (PARTITION BY DEPARTMENTNO ORDER BY
DEPARTMENTNO ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING)
FROM EMPLOYEE2;
The
Group Sum reflects the total for each department.
The
key words ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED
FOLLOWING are unnecessary since they are the default.
|
Blog Archive
-
►
2012
(22)
- ► January 2012 (21)
- ► February 2012 (1)
-
▼
2013
(119)
- ► February 2013 (2)
- ► March 2013 (28)
-
▼
April 2013
(48)
- String To Date Conversion (Date CASTing)
- Teradata DATE-TIME Part 1 - Date Standard formats ...
- Teradata DATE-TIME part 2 - DATEFORM
- Teradata DATE-TIME Part 3 - INTERVAL datatype
- Teradata DATE-TIME Part 4 - YEAR MONTH DAY interval
- Teradata DATE-TIME interval Part 5 - Date subtraction
- Teradata DATE-TIME interval part 6 - Casting Terad...
- Teradata DATE-TIME part 7 - Extracting YEAR,MONTH ...
- TeraData DATE-TIME part 8 - TIME datatype
- Teradata Date Time - Part 9 DAY-TIME interval
- Teradata Date Time - Part 10 - Combining Time with...
- Teradata Date Time Part 11 - Time subtraction
- Teradata Date Time Part 12 - Casting Date Time int...
- Teradata Timestamp Part 1
- Teradata Date Time Part 13 -- Adding two TIMES is ...
- Teradata Timestamp Part 2- Timestamp subtraction
- Teradata Timestamp Part 3 - Timestamp casting
- Teradata timestamp - Part 4 - TIMESTAMP/TIME with ...
- Teradata Timestamp - Part 5 - Setting up Time Zone
- Teradata Timestamp - Part 6 - Time Zone Normalizat...
- Teradata Timestamp - Part 7 - Extracting from Tera...
- Teradata DEFAULT VALUES.
- Teradata - Adding a NOT NULL column to table using...
- Teradata Renaming Columns
- Case Sensitivity in Teradata
- Teradata RANDOM function, INDEX Function, POSITION...
- Creating Tables using Existing tables - WITH DATA/...
- Creating Tables using Subqueries
- Teradata COUNT window Function - Generating totals...
- Relationship between COUNT OVER, QUANTILE and PERC...
- TeraData SUM OVER function - Calculating Grand Tot...
- Finding Individual contribution using SUM OVER (SU...
- ANSI and Teradata Function Equivalents - Part 1- ...
- ANSI and Teradata Function Equivalents - Part 2 - ...
- ANSI and Teradata Function Equivalents - Part 3 - ...
- ANSI and Teradata Function Equivalents - Part 4 - ...
- ANSI and Teradata Function Equivalents - Part 5 - ...
- Teradata Stored Procedures - Introduction
- Teradata Stored Procedures - Casting Call Argument...
- Teradata Stored Procedures: Passing Arguments usin...
- Teradata Stored Procedures - Calling a Procedure w...
- Teradata ROW_NUMBER
- Teradata SUM Window Function
- Teradata MIN Window function
- Teradata MAX window Function
- Teradata Cumulative SUM using SUM WINDOW function
- Teradata Cumulative MAX/MIN using MAX/MIN window f...
- Teradata Moving SUM using SUM window Function - RO...
- ► September 2013 (16)
- ► October 2013 (3)
- ► November 2013 (13)
Sunday, 28 April 2013
Teradata SUM Window Function
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment