Back to SQL Course - Back to Operators
Arithmetic Performs math operation on numerical data, we can find addition, subtraction, multiplication, division and modulus.
Performs the addition operation on numerical data.
SELECT OPERAND1 + OPERAND2;
-- simple sum
SELECT 10 + 20
-- sum between a column and a number
SELECT price + 20 FROM products;
-- sum between two columns of a table
SELECT price + tax FROM products;
Performs the subtraction operation on numerical data.
SELECT OPERAND1 - OPERAND2;
-- simple subtraction
SELECT 20 - 20;
-- subtraction between a column and a number
SELECT price - 20 FROM products;
-- subtraction between two columns of a table
SELECT price - tax FROM products;
Performs the multiplication operation on numerical data.
SELECT OPERAND1 * OPERAND2;
-- simple multiplication
SELECT 10 * 20;
-- multiplication between a column and a number
SELECT price * 2 FROM products;
-- multiplication between two columns of a table
SELECT price * quantity from products;
Performs the division operation on numerical data.
SELECT OPERAND1 / OPERAND2;
-- simple division
SELECT 10 / 2;
-- division between a column and a number
SELECT price / 2 FROM products;
-- division between two columns of a table
SELECT price / quantity FROM products;
Returns the remainder of a division operation on numerical data.
SELECT OPERAND1 % OPERAND2;
-- simple modulus, returns 1
SELECT 5 % 2;
-- modulus between a column and a number
SELECT price % 2 FROM products;
-- modulus between two columns of a table
SELECT price % tax FROM products;
Back to SQL Course - Back to Operators
Let’s connect
If you want to learn more about the topic, connect or send me a DM.