fg

fg

Posts

Arithmetic Expressions - Operator Precedence


Description:
1- perform any calculations inside parentheses.
2- perform all multiplications and divisions, working from left to right.
3- perform all additions and subtractions, working from left to right.


Examples: 
 
SELECT last_name, salary, 12*salary+100
FROM   employees;

The select statement displays the last name, salary, and annual compensation of employees. It calculates the annual compensation by multiplying the monthly salary with 12, plus a one-time bonus of $100.
Note that multiplication is performed before addition.


SELECT last_name, salary, 12*(salary+100)
FROM   employees;

The select statement displays the last name, salary, and annual compensation of employees. It calculates the annual compensation as follows:
adding a monthly bonus of $100 to the monthly salary, and then multiplying that subtotal with 12. Because of the parentheses, addition takes priority over multiplication.




No comments :

Post a Comment