Arithmetic Expression in SQL

 Create expression with number and data by using Arithmetic Expression.

Operators in Arithmetic Expression:

Operators  Description
+  Additional
 Subtraction
*  Multiplication
/  Division

Operators Precedence :

  1. Multiplication ( * )
  2. Division ( / )
  3. Addition ( + )
  4. Subtraction ( )
  • Multiplication and division takes priority over addition and subtraction.
  • Operators of the same priority are evaluated from Left to Right.
  • parenthesis ( ) are used to force priority evaluation and to clarify statements.

Examples :

Question : To display annual salary from employee table.

Query :   SELECT ename, sal, sal*12  As  “annual sal”  from emp;

Output :       ename      sal      annual sal

    smith       800      9600

Question : Display all the employee annual salary with early bonus of 1000$.

Query :   SELECT ename, sal, (sal+1000)*12  As  “annual sal”  from emp;

Output :       ename      sal      annual sal

   smith        800         10600


NULL VALUE :

  • A null value is a value that is unavailable unassigned, unknown or inapplicable
  • A null is not the same as a zero or a blank space
  • Arithmetic Expression containing a null value evaluate to null.

Example :

Question : Display salary + commission from employee table.

Query :   SELECT ename, sal, comm, sal+comm  As  monthlysal  from emp;

Output :       ename      sal         comm          monthlysal 

   smith        800

   allen        1600        300                    1900

                      john         1250        500                    1750