SUM window Cumulative
Function:
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
SUM
window function allows cumulative aggregate to be calculated.
Teradata equivalent is CSUM function. To get cumulative SUM we use UNBOUNDED PRECEDING as follows: SELECT EMPLOYEEID,DEPARTMENTNO,SALARY,
SUM(SALARY) OVER (
ORDER BY
DEPARTMENTNO ROWS UNBOUNDED PRECEDING
)
FROM EMPLOYEE2;
Cumulative
Sum is nothing but sequential aggregation .
Note
that the Column title indicates that its 'Cumulative SUM'
We
can reset the cumulative SUM by making use of PARTITION BY clause as follows:
SELECT EMPLOYEEID,DEPARTMENTNO,SALARY,
SUM(SALARY) OVER (
PARTITION BY DEPARTMENTNO
ORDER BY
DEPARTMENTNO ROWS UNBOUNDED PRECEDING
)
FROM EMPLOYEE2;
|
Pages
▼
No comments:
Post a Comment