SUM
Overview
The SUM()
window function returns the sum of the input column or expression values.
Syntax
The syntax for this function is as follows:
The expression’s argument types supported by the SUM
window function are INTEGER
, BIGINT
, REAL
and DOUBLE PRECISION
. The return types of the SUM
function are: BIGINT
for integer and DOUBLE PRECISION
for floating-point arguments.
SUM()
window function works with numeric values and ignores NULL onesParameters
expression
: input’s column or expression values to be summed
Examples
For the needs of this section, we will create the winsales
table that stores details of some sales transactions:
SUM() with ORDER BY
In this example, we will focus on executing the SUM()
window function with ORDER BY
keyword:
The output from the above query includes the sales ID, date ID, seller ID, quantity and quantity sum:
SUM() with ORDER BY and PARTITION BY
In this example we will focus on executing the SUM()
function with ORDER BY
keyword and PARTITION BY
clause:
After executing the query above, we get the following output: