Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
58 views

Arithmetic Operators - SQL

The document discusses SQL arithmetic operators such as plus, minus, divide, multiply, and modulo. It provides examples of how to use each operator in queries, including adding or subtracting values, multiplying prices by a discount rate, and renaming columns with aliases. Parentheses are important for determining order of operations. The modulo operator returns the integer remainder of a division.

Uploaded by

Kristine Capao
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
58 views

Arithmetic Operators - SQL

The document discusses SQL arithmetic operators such as plus, minus, divide, multiply, and modulo. It provides examples of how to use each operator in queries, including adding or subtracting values, multiplying prices by a discount rate, and renaming columns with aliases. Parentheses are important for determining order of operations. The modulo operator returns the integer remainder of a division.

Uploaded by

Kristine Capao
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 25

OPERATORS

ARITHMETIC OPERATORS
SQL

Ppt Template by: https://poweredtemplate.com/04066/0/index.html


Arithmetic Operators

• Plus (+)
• Minus (-)
• Divide (/)
• Multiply (*)
• Modulo (%)
– returns the integer remainder of a division
 The modulo operator does not work
with data types that have decimals.

Ppt Template by: https://poweredtemplate.com/04066/0/index.html


Arithmetic Operators: Modulo (%)

102 % 5 = 2

Ppt Template by: https://poweredtemplate.com/04066/0/index.html


Arithmetic Operators

2 * 6 +9 / 3
evaluated as

12 + 3 = 15

Ppt Template by: https://poweredtemplate.com/04066/0/index.html


Arithmetic Operators

However,

2 * (6 + 9 ) / 3
evaluated as

2 * 15 / 3 = 10 MDAS

 Watch where you put those parentheses! Sometimes


the expression does exactly what you tell it to do,
rather than what you want it to do.

Ppt Template by: https://poweredtemplate.com/04066/0/index.html


Arithmetic Operators: Example Queries

• SELECT ITEM, WHOLESALE,


WHOLESALE + 0.15 FROM
PRICE;

The (+) in
adds 15 cents to each price.
Thus, the query above will produce the
following results.

Ppt Template by: https://poweredtemplate.com/04066/0/index.html


Arithmetic Operators: Example Queries

Ppt Template by: https://poweredtemplate.com/04066/0/index.html


Arithmetic Operators: Example Queries

• SELECT ITEM, WHOLESALE,


(WHOLESALE + 0.15) AS RETAIL
FROM PRICE;

This command Rename the


segment will column name as
adds 15 cents to RETAIL from
each price WHOLESALE + 0.15

Ppt Template by: https://poweredtemplate.com/04066/0/index.html


Arithmetic Operators: Example Queries

Ppt Template by: https://poweredtemplate.com/04066/0/index.html


Arithmetic Operators: Example Queries

• SELECT ITEM, WHOLESALE,


(WHOLESALE + 0.15) AS RETAIL
FROM PRICE;

Column name Alias

Ppt Template by: https://poweredtemplate.com/04066/0/index.html


Arithmetic Operators: Example Queries

• What if we omit the parenthesis in


the query like this?
 SELECT ITEM, WHOLESALE,
WHOLESALE + 0.15 AS RETAIL FROM
PRICE; Rename the
column name as
RETAIL from
WHOLESALE + 0.15

Ppt Template by: https://poweredtemplate.com/04066/0/index.html


Arithmetic Operators: Example Queries

Ppt Template by: https://poweredtemplate.com/04066/0/index.html


Arithmetic Operators: Example Queries

 What will be the query if the result is

ANSWER

Ppt Template by: https://poweredtemplate.com/04066/0/index.html


Arithmetic Operators: Minus ( - )

1. It can change the sign of a


number.
2. To subtract.
Rename the
column name as
RETAIL from
WHOLESALE + 0.15

Ppt Template by: https://poweredtemplate.com/04066/0/index.html


Arithmetic Operators: Minus ( - )

1. It can change the sign of a number.

What is the query?


ANSWER

Ppt Template by: https://poweredtemplate.com/04066/0/index.html


Arithmetic Operators: Minus ( - )

2. To subtract.
i. Subtracting one column to another
ii. Subtracting values to data.

Ppt Template by: https://poweredtemplate.com/04066/0/index.html


Arithmetic Operators: Minus ( - )

2. To subtract.
i. Subtracting one column to another

What is the query?


ANSWER

Ppt Template by: https://poweredtemplate.com/04066/0/index.html


 Renaming column names using
aliases as just temporary. It will not
change the column names as defined
in its table structure.

Ppt Template by: https://poweredtemplate.com/04066/0/index.html


Arithmetic Operators: Divide ( / )

• The division operator has only the one


obvious meaning.
 SELECT ITEM, WHOLESALE,
(WHOLESALE/2) as SALEPRICE FROM
PRICE;
What is the query result?

Ppt Template by: https://poweredtemplate.com/04066/0/index.html


Arithmetic Operators: Multiple ( * )

• The multiplication operator is also


straightforward.
 Change the PRICE table by reflecting (add
new column) an across-the-board 10 percent
discount.

SELECT ITEM,
WHOLESALE,
WHOLESALE * 0.9
as NEWPRICE
FROM PRICE;

Ppt Template by: https://poweredtemplate.com/04066/0/index.html


Ppt Template by: https://poweredtemplate.com/04066/0/index.html
Ppt Template by: https://poweredtemplate.com/04066/0/index.html
Arithmetic Operators: Example Queries

• SELECT ITEM AS PRODUCT,


WHOLESALE, WHOLESALE + 0.25
AS RETAIL FROM PRICE;

Rename the
column name as
RETAIL from
WHOLESALE + 0.15

Ppt Template by: https://poweredtemplate.com/04066/0/index.html


Arithmetic Operators: Example Queries

• SELECT STATE, -HIGHTEMP as


LOWS, -LOWTEMP as HIGHS
FROM HILOW;

Rename the
column name as
RETAIL from
WHOLESALE + 0.15

Ppt Template by: https://poweredtemplate.com/04066/0/index.html


Arithmetic Operators: Example Queries

• SELECT STATE, HIGHTEMP as


LOWS, LOWTEMP as HIGHS,
(LOWTEMP - HIGHTEMP) as
DIFFERENCE FROM HILOW;
Rename the
column name as
RETAIL from
WHOLESALE + 0.15

Ppt Template by: https://poweredtemplate.com/04066/0/index.html

You might also like