MySQL arithmetic functions allow you to perform mathematical calculations directly inside SQL queries. They are commonly used to compute totals, differences, ratios, rounding values, and numeric transformations.
MySQL supports both operators and built-in functions to perform arithmetic operations such as addition, subtraction, multiplication, division, rounding, and square root calculations.
// Adds two numbers and returns their sum
SELECT 10 + 5 AS sum;
// Subtracts one value from another
SELECT 10 - 5 AS difference;
// Multiplies two numeric values
SELECT 10 * 5 AS product;
// Divides one number by another
SELECT 10 / 5 AS quotient;
// Returns the remainder of a division
SELECT 10 % 3 AS remainder;
// Converts negative values into positive values
SELECT ABS(-10) AS absolute_value;
// Calculates the square root of a number
SELECT SQRT(16) AS square_root;
// Rounds a number to two decimal places
SELECT ROUND(10.567, 2) AS rounded_number;
Each query returns a calculated value based on the operation applied. These results can be used directly in reports, calculations, or further SQL expressions.
Try combining multiple arithmetic functions together:
// Combines ABS, division, and ROUND together
SELECT ROUND(ABS(-12.345) / 2, 1) AS final_result;