MySQL Arithmetic Operators

You may not always want to retrieve the data as is. In some cases, you may want to display your data with certain calculation, or look at a what-if scenarios (for example, you may want to know how the prices would look like after adding VAT).

The MySQL query in this example calculates the book’s price after an addition of 20%.

SELECT bookName , Publisher, bookPrice, bookPrice * 1.2
FROM books

It is advisable to specify the original column without the change (bookPrice) in addition to the column with the calculation (bookPrice *1.2), in order to make the difference – in this example, the increase – visible.

Note : MySQL syntax Ignores blank spaces before and after the arithmetic operator.

Arithmetic Operations on NULL Values

In MySQL A NULL value is a value that indicates an empty field in a table. This value does not equal zero (0), nor does it equal space (‘ ‘); When a certain calculation is carried out on a column that contains NULL values, any calculation performed on the NULL value returns NULL.