SQL: JOINS - Advanced SQL Commands - Mathematical Functions

Mathematical Functions

The mathematical functions are used to manipulate the dataset. More information on mathematical functions!

Syntax:

-- Mathematical Function
SELECT column_1 + column_2 as new_column
FROM table_1;

Example: Create a new column by adding the customer_id and rental_id

-- Create a new column by adding the customer_id and rental_id
SELECT customer_id + rental_id as sum_id
FROM payment
limit 20;
##    sum_id
## 1    1861
## 2    2119
## 3    2190
## 4    3170
## 5    3471
## 6    3723
## 7    2532
## 8    3256
## 9    3423
## 10   1890
## 11   1907
## 12   2222
## 13   2265
## 14   2804
## 15   3323
## 16   3750
## 17   1685
## 18   1819
## 19   2075
## 20   1555

Example: Create a new column by multiplying the customer_id and rental_id

-- Create a new column by multiplying the customer_id and rental_id
SELECT customer_id * rental_id as sum_id
FROM payment
limit 20;
##     sum_id
## 1   518320
## 2   606298
## 3   630509
## 4   964689
## 5  1067330
## 6  1153262
## 7   748980
## 8   996588
## 9  1053702
## 10  530621
## 11  536452
## 12  644497
## 13  659246
## 14  844123
## 15 1022140
## 16 1168601
## 17  461304
## 18  507400
## 19  595464
## 20  417450