Number - Addition (or Sum, Sigma) or Total

1 - About

The addition of all numbers in a set is called a total.

Sum can be use as:

It can follow the full syntax of the analytic function and in this way create Function - (Moving|Rolling|Running) Calculation

It's a binary function.

3 - Associative Property

An addition has an associative property and groups to the left (i.e., is left-associative). 1 + 2 + 3 is equivalent to (1 + 2 ) + 3

Example in Javascript

console.log(1 + 2 + 3); // 6
console.log((1 + 2) + 3); // 6
console.log(1 + "2" + 3); // 123
console.log((1 + "2") + 3); // 123

4 - Different Methods

An addition can be:

The two arithmetic operations work on different types of operands and require different functions.

5 - Sigma

The symbol “sigma” is the Greek capital S and is a shortcut for “the sum of”.

  • sum of x: sum{}{}{x}

6 - Analytic / Aggregate

The data come from the sample schema SH and the two next statements retrieve the same result.

6.1 - Aggregate (Group By)

select distinct CUST_LAST_NAME, sum(AMOUNT_SOLD)  
from 
   SH.CUSTOMERS CUST,
   SH.SALES SALES
where  ( CUST.CUST_ID = SALES.CUST_ID ) AND
( CUST_LAST_NAME like 'Aa%' or CUST_LAST_NAME like 'Ab%' or CUST_LAST_NAME like 'Ac%' )
group by CUST_LAST_NAME
order by CUST_LAST_NAME asc

6.2 - Analytic / Window (Over )

select distinct CUST_LAST_NAME, sum(AMOUNT_SOLD)  over (order by CUST_LAST_NAME)
from 
   SH.CUSTOMERS CUST,
   SH.SALES SALES
where  ( CUST.CUST_ID = SALES.CUST_ID ) AND
( CUST_LAST_NAME like 'Aa%' or CUST_LAST_NAME like 'Ab%' or CUST_LAST_NAME like 'Ac%' )
order by CUST_LAST_NAME asc

6.3 - Analytic and Aggregate Statement

select 
    distinct CUST_LAST_NAME, 
    sum(AMOUNT_SOLD) ,
    sum(sum(AMOUNT_SOLD) over () -- Grand Total. You must give the two times the SUM function. Otherwise you get a ORA-00979.
from 
   SH.CUSTOMERS CUST,
   SH.SALES SALES
where  ( CUST.CUST_ID = SALES.CUST_ID ) AND
( CUST_LAST_NAME like 'Aa%' or CUST_LAST_NAME like 'Ab%' or CUST_LAST_NAME like 'Ac%' )
group by CUST_LAST_NAME
order by CUST_LAST_NAME asc

7 - Identity

The identity function for addition (+) is <MATH> x+0 = x </MATH>

8 - Reference


Data Science
Data Analysis
Statistics
Data Science
Linear Algebra Mathematics
Trigonometry

Powered by ComboStrap