Tuesday 13 January 2015

Using Arithmetic Operators in SQL Statements

You can create custom arithmetic expressions in your SELECT statement with the help of the common arithmetic operators defined in the table below. Besides SELECT, you are allowed to use these operators in any clause of a SQL statement except the FROM clause.

Operator
Description
+
Add
-
Subtract
*
Multiply
/
Divide

The following example uses the multiplication operator to display annual salary of all employees (by multiplying values in the table’s salary column with a constant value i.e. 12) along with their commission percentages.  Note that the resultant salary column (SALARY * 12) is not actually created in the Employees table, but is generated for display purpose only.


    SQL Statement :

SELECT   last_name, salary * 12, commission_pct
FROM      employees;

    Output :


















No comments:

Post a Comment