SQLite Arithmetic Operators
SQLite Arithmetic Operators
This tutorial will teach you SQLite Arithmetic operators and illustrate their usage with some examples. Arithmetic operators are used to perform mathematical calculations.
SQLite Arithmetic operators are as follows in a table format:
SQLite Operator |
Name | Description |
+ | Addition Operator | The + operator adds two operands. |
– | Subtraction Operator | The – operator subtracts the right operand from the left operand. |
* | Multiplication Operator | The * operator multiplies two operands. |
/ | Division Operator | The / operator divides the left operand by the right-hand operand and returns the result. |
% | Modulus Operator | The % operator returns the remainder of the division of the left operand by the right operand. |
Example
Let’s understand the operators with the help of examples.
sqlite> SELECT 7 + 9 AS SUM;
SUM
—
16
sqlite> SELECT 9 – 7 AS DIFF;
DIFF
—-
2
sqlite> SELECT 7 * 9 AS PRODUCT;
PRODUCT
——-
63
sqlite> SELECT 9 % 7 AS REM;
REM
—
2
sqlite> SELECT 9 / 7 AS RESULT;
RESULT
——
1
The above result is wrong. Since 7 doesn’t exactly divide 9, the result should be a real or floating point value.
sqlite> SELECT 9.0 / 7.0 AS RESULT;
RESULT
—————-
1.28571428571429
Let’s see how to use the arithmetic operators on table columns:
sqlite> SELECT ename, 2*salary AS DoubleSalary FROM emp;
ename          DoubleSalary
————Â Â Â Â Â Â Â ————
John Smith      5000
Emma Johnson  19000
—
SQLite Tutorials
SQLite tutorials on this website:
https://www.testingdocs.com/sqlite-database-tutorials/
For more information on SQLite, visit the official website: