0% found this document useful (0 votes)
5 views26 pages

Operator

The document explains various arithmetic and comparison operators in SQL, including addition, subtraction, multiplication, division, and modulus, along with their syntax and examples. It also covers comparison operators such as equal, not equal, greater than, less than, and their usage in queries. Additionally, the document introduces the MySQL GROUP BY clause for aggregating data from multiple records based on specified columns.

Uploaded by

dhassahil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views26 pages

Operator

The document explains various arithmetic and comparison operators in SQL, including addition, subtraction, multiplication, division, and modulus, along with their syntax and examples. It also covers comparison operators such as equal, not equal, greater than, less than, and their usage in queries. Additionally, the document introduces the MySQL GROUP BY clause for aggregating data from multiple records based on specified columns.

Uploaded by

dhassahil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 26

Following are the various arithmetic operators performed on the SQL data:

1. SQL Addition Operator (+)


2. SQL Subtraction Operator (-)
3. SQL Multiplication Operator (+)
4. SQL Division Operator (-)
5. SQL Modulus Operator (+)

SQL Addition Operator (+)


The Addition Operator in SQL performs the addition on the numerical data of the database
table. In SQL, we can easily add the numerical values of two columns of the same table by
specifying both the column names as the first and second operand. We can also add the numbers
to the existing numbers of the specific column.

Syntax of SQL Addition Operator:

1. SELECT operand1 + operand2;

Let's understand the below example which explains how to execute Addition
Operator in SQL query:

This example consists of an Employee_details table, which has four columns Emp_Id,
Emp_Name, Emp_Salary, and Emp_Monthlybonus.

Emp Id Emp Name Emp Salary Emp Monthlybonus

101 Tushar 25000 4000

102 Anuj 30000 200

o Suppose, we want to add 20,000 to the salary of each employee specified in the table.
Then, we have to write the following query in the SQL:

1. SELECT Emp_Salary + 20000 as Emp_New_Salary FROM Employee_details;

In this query, we have performed the SQL addition operation on the single column of the given
table.
o Suppose, we want to add the Salary and monthly bonus columns of the above table,
then we have to write the following query in SQL:

1. SELECT Emp_Salary + Emp_Monthlybonus as Emp_Total_Salary FROM Employee_details;

In this query, we have added two columns with each other of the above table.

SQL Subtraction Operator (-)


The Subtraction Operator in SQL performs the subtraction on the numerical data of the database
table. In SQL, we can easily subtract the numerical values of two columns of the same table by
specifying both the column names as the first and second operand. We can also subtract the
number from the existing number of the specific table column.

Syntax of SQL Subtraction Operator:

1. SELECT operand1 - operand2;

Let's understand the below example which explains how to execute Subtraction
Operator in SQL query:

This example consists of an Employee_details table, which has four columns Emp_Id,
Emp_Name, Emp_Salary, and Emp_Monthlybonus.

Emp Id Emp Name Emp Salary Penalty

201 Abhay 25000 200

202 Sumit 30000 500

o Suppose we want to subtract 5,000 from the salary of each employee given in
the Employee_details table. Then, we have to write the following query in the SQL:

1. SELECT Emp_Salary - 5000 as Emp_New_Salary FROM Employee_details;

In this query, we have performed the SQL subtraction operation on the single column of the
given table.

o If we want to subtract the penalty from the salary of each employee, then we have to
write the following query in SQL:
1. SELECT Emp_Salary - Penalty as Emp_Total_Salary FROM Employee_details;

SQL Multiplication Operator (*)


The Multiplication Operator in SQL performs the Multiplication on the numerical data of the
database table. In SQL, we can easily multiply the numerical values of two columns of the same
table by specifying both the column names as the first and second operand.

Syntax of SQL Multiplication Operator:

1. SELECT operand1 * operand2;

Let's understand the below example which explains how to execute Multiplication
Operator in SQL query:

This example consists of an Employee_details table, which has four columns Emp_Id,
Emp_Name, Emp_Salary, and Emp_Monthlybonus.

Emp Id Emp Name Emp Salary Penalty

201 Abhay 25000 200

202 Sumit 30000 500

o Suppose, we want to double the salary of each employee given in


the Employee_details table. Then, we have to write the following query in the SQL:

1. SELECT Emp_Salary * 2 as Emp_New_Salary FROM Employee_details;

In this query, we have performed the SQL multiplication operation on the single column
of the given table.

o If we want to multiply the Emp_Id column to Emp_Salary column of that employee


whose Emp_Id is 202, then we have to write the following query in SQL:

1.

SELECT Emp_Id * Emp_Salary as Emp_Id * Emp_Salary FROM Employee_details WHERE E


mp_Id = 202;
In this query, we have multiplied the values of two columns by using the WHERE
clause.

SQL Division Operator (/)


The Division Operator in SQL divides the operand on the left side by the operand on the
right side.

Syntax of SQL Division Operator:

1. SELECT operand1 / operand2;

In SQL, we can also divide the numerical values of one column by another column of
the same table by specifying both column names as the first and second operand.

We can also perform the division operation on the stored numbers in the column of the
SQL table.

Let's understand the below example which explains how to execute Division
Operator in SQL query:

This example consists of an Employee_details table, which has three


columns Emp_Id, Emp_Name, and Emp_Salary.

Emp Id Emp Name Emp Salary

201 Abhay 25000

202 Sumit 30000

o Suppose, we want to half the salary of each employee given in the Employee_details
table. For this operation, we have to write the following query in the SQL:

1. SELECT Emp_Salary / 2 as Emp_New_Salary FROM Employee_details;

In this query, we have performed the SQL division operation on the single column of the
given table.

SQL Modulus Operator (%)


The Modulus Operator in SQL provides the remainder when the operand on the left side
is divided by the operand on the right side.

Syntax of SQL Modulus Operator:

1. SELECT operand1 % operand2;

Let's understand the below example which explains how to execute Modulus
Operator in SQL query:

This example consists of a Division table, which has three columns Number,
First_operand, and Second_operand.

Number First operand Second operand

1 56 4

2 32 8

3 89 9

4 18 10

5 10 5

o If we want to get the remainder by dividing the numbers of First_operand column by the
numbers of Second_operand column, then we have to write the following query in SQL:

1. SELECT First_operand % Second_operand as Remainder FROM Employee_details;

SQL Comparison Operators


The Comparison Operators in SQL compare two different data of SQL table and
check whether they are the same, greater, and lesser. The SQL comparison operators
are used with the WHERE clause in the SQL queries

Following are the various comparison operators which are performed on the data
stored in the SQL database tables:

1. SQL Equal Operator (=)


2. SQL Not Equal Operator (!=)
3. SQL Greater Than Operator (>)
4. SQL Greater Than Equals to Operator (>=)
5. SQL Less Than Operator (<)\
6. SQL Less Than Equals to Operator (<=)

SQL Equal Operator (=)


This operator is highly used in SQL queries. The Equal Operator in SQL shows only
data that matches the specified value in the query.

This operator returns TRUE records from the database table if the value of both
operands specified in the query is matched.

Let's understand the below example which explains how to execute Equal
Operator in SQL query:

This example consists of an Employee_details table, which has three


columns Emp_Id, Emp_Name, and Emp_Salary.

Emp Id Emp Name Emp Salary

201 Abhay 30000

202 Ankit 40000

203 Bheem 30000

204 Ram 29000

205 Sumit 30000

o Suppose, we want to access all the records of those employees from


the Employee_details table whose salary is 30000. Then, we have to write the following
query in the SQL database:

1. SELECT * FROM Employee_details WHERE Emp_Salary = 30000;


In this example, we used the SQL equal operator with WHERE clause for getting the
records of those employees whose salary is 30000.

SQL Equal Not Operator (!=)


The Equal Not Operator in SQL shows only those data that do not match the query's
specified value.

This operator returns those records or rows from the database views and tables if the
value of both operands specified in the query is not matched with each other.

Let's understand the below example which explains how to execute Equal Not
Operator in SQL query:

This example consists of an Employee_details table, which has three


columns Emp_Id, Emp_Name, and Emp_Salary.

Emp Id Emp Name Emp Salary

201 Abhay 45000

202 Ankit 45000

203 Bheem 30000

204 Ram 29000

205 Sumit 29000

o Suppose, we want to access all the records of those employees from


the Employee_details table whose salary is not 45000. Then, we have to write the
following query in the SQL database:

1. SELECT * FROM Employee_details WHERE Emp_Salary != 45000;

In this example, we used the SQL equal not operator with WHERE clause for getting the
records of those employees whose salary is not 45000.

SQL Greater Than Operator (>)


The Greater Than Operator in SQL shows only those data which are greater than the
value of the right-hand operand.

Let's understand the below example which explains how to execute Greater
ThanOperator (>) in SQL query:

This example consists of an Employee_details table, which has three


columns Emp_Id, Emp_Name, and Emp_Salary.

Emp Id Emp Name Emp Salary

201 Abhay 45000

202 Ankit 45000

203 Bheem 30000

204 Ram 29000

205 Sumit 29000

o Suppose, we want to access all the records of those employees from


the Employee_details table whose employee id is greater than 202. Then, we have to
write the following query in the SQL database:

1. SELECT * FROM Employee_details WHERE Emp_Id > 202;

Here, SQL greater than operator displays the records of those employees from the
above table whose Employee Id is greater than 202.

SQL Greater Than Equals to Operator (>=)


The Greater Than Equals to Operator in SQL shows those data from the table which
are greater than and equal to the value of the right-hand operand.

Let's understand the below example which explains how to execute greater than
equals to the operator (>=) in SQL query:

This example consists of an Employee_details table, which has three


columns Emp_Id, Emp_Name, and Emp_Salary.
Emp Id Emp Name Emp Salary

201 Abhay 45000

202 Ankit 45000

203 Bheem 30000

204 Ram 29000

205 Sumit 29000

o Suppose, we want to access all the records of those employees from


the Employee_details table whose employee id is greater than and equals to 202. For
this, we have to write the following query in the SQL database:

1. SELECT * FROM Employee_details WHERE Emp_Id >= 202;

Here,'SQL greater than equals to operator' with WHERE clause displays the rows of
those employees from the table whose Employee Id is greater than and equals to 202.

SQL Less Than Operator (<)


The Less Than Operator in SQL shows only those data from the database tables
which are less than the value of the right-side operand.

This comparison operator checks that the left side operand is lesser than the right side
operand. If the condition becomes true, then this operator in SQL displays the data
which is less than the value of the right-side operand.

Let's understand the below example which explains how to execute less than
operator (<) in SQL query:

This example consists of an Employee_details table, which has three


columns Emp_Id, Emp_Name, and Emp_Salary.

Emp Id Emp Name Emp Salary

201 Abhay 45000


202 Ankit 45000

203 Bheem 30000

204 Ram 29000

205 Sumit 29000

o Suppose, we want to access all the records of those employees from


the Employee_details table whose employee id is less than 204. For this, we have to
write the following query in the SQL database:

1. SELECT * FROM Employee_details WHERE Emp_Id < 204;

Here,SQL less than operator with WHERE clause displays the records of those
employees from the above table whose Employee Id is less than 204.

SQL Less Than Equals to Operator (<=)


The Less Than Equals to Operator in SQL shows those data from the table which are
lesser and equal to the value of the right-side operand.

This comparison operator checks that the left side operand is lesser and equal to the
right side operand.

Let's understand the below example which explains how to execute less than
equals to the operator (<=) in SQL query:

This example consists of an Employee_details table, which has three


columns Emp_Id, Emp_Name, and Emp_Salary.

Emp Id Emp Name Emp Salary

201 Abhay 45000

202 Ankit 45000

203 Bheem 30000


204 Ram 29000

205 Sumit 29000

o Suppose, we want to access all the records of those employees from


the Employee_details table whose employee id is less and equals 203. For this, we
have to write the following query in the SQL database:

1. SELECT * FROM Employee_details WHERE Emp_Id <= 203;

Here, SQL less than equals to the operator with WHERE clause displays the rows of
those employees from the table whose Employee Id is less than and equals 202.

MySQL GROUP BY Clause


The MYSQL GROUP BY Clause is used to collect data from multiple records and group
the result by one or more column. It is generally used in a SELECT statement.

You can also use some aggregate functions like COUNT, SUM, MIN, MAX, AVG etc. on
the grouped column.

Syntax:

1. SELECT expression1, expression2, ... expression_n,


2. aggregate_function (expression)
3. FROM tables
4. [WHERE conditions]
5. GROUP BY expression1, expression2, ... expression_n;
Parameters
expression1, expression2, ... expression_n: It specifies the expressions that are not
encapsulated within an aggregate function and must be included in the GROUP BY
clause.

Play Video

aggregate_function: It specifies a function such as SUM, COUNT, MIN, MAX, or AVG


etc. tables: It specifies the tables, from where you want to retrieve the records. There
must be at least one table listed in the FROM clause.
WHERE conditions: It is optional. It specifies the conditions that must be fulfilled for
the records to be selected.

(i) MySQL GROUP BY Clause with COUNT function


Consider a table named "officers" table, having the following records.

Now, let's count repetitive number of cities in the column address.

Execute the following query:

1. SELECT address, COUNT(*)


2. FROM officers
3. GROUP BY address;

Output:
(ii) MySQL GROUP BY Clause with SUM function
Let's take a table "employees" table, having the following data.

Now, the following query will GROUP BY the example using the SUM function and
return the emp_name and total working hours of each employee.

Execute the following query:


1. SELECT emp_name, SUM(working_hours) AS "Total working hours"
2. FROM employees
3. GROUP BY emp_name;

Output:

(iii) MySQL GROUP BY Clause with MIN function


The following example specifies the minimum working hours of the employees form the
table "employees".

Execute the following query:

1. SELECT emp_name, MIN(working_hours) AS "Minimum working hour"


2. FROM employees
3. GROUP BY emp_name;

Output:
(iv) MySQL GROUP BY Clause with MAX function
The following example specifies the maximum working hours of the employees form the
table "employees".

Execute the following query:

1. SELECT emp_name, MAX (working_hours) AS "Minimum working hour"


2. FROM employees
3. GROUP BY emp_name;

Output:
(v) MySQL GROUP BY Clause with AVG function
The following example specifies the average working hours of the employees form the table
"employees".

Execute the following query:

1. SELECT emp_name, AVG(working_hours) AS "Average working hour"


2. FROM employees
3. GROUP BY emp_name;

Output:
MySQL Boolean
A Boolean is the simplest data type that always returns two possible values, either true
or false. It can always use to get a confirmation in the form of YES or No value.

MySQL does not contain built-in Boolean or Bool data type. They provide
a TINYINT data type instead of Boolean or Bool data types. MySQL considered value
zero as false and non-zero value as true. If you want to use Boolean literals, use true or
false that always evaluates to 0 and 1 value. The 0 and 1 represent the integer values.

Execute the following statement to see the integer values of Boolean literals:

1. Mysql> Select TRUE, FALSE, true, false, True, False;

After successful execution, the following result appears:

4.3M

118

iSpoof shuts down after an international criminal investigation

MySQL Boolean Example


We can store a Boolean value in the MySQL table as an integer data type. Let us create
a table student that demonstrates the use of Boolean data type in MySQL:

1. mysql> CREATE TABLE student (


2. studentid INT PRIMARY KEY AUTO_INCREMENT,
3. name VARCHAR(40) NOT NULL,
4. age VARCHAR(3),
5. pass BOOLEAN
6. );

In the above query, we can see that the pass field is defined as a Boolean when
showing the definition of a table; it contains TINIINT as follows:

1. mysql> DESCRIBE student;

Let us add two new rows in the above table with the help of following query:

1. mysql> INSERT INTO student(name, pass) VALUES('Peter',true), ('John',false);

When the above query executed, immediately MySQL checks for the Boolean data type
in the table. If the Boolean literals found, it will be converted into integer values 0 and 1.
Execute the following query to get the data from the student table:

1. Mysql> SELECT studentid, name, pass FROM student;

You will get the following output where the true and false literal gets converted into 0
and 1 value.

Since MySQL always use TINYINT as Boolean, we can also insert any integer values
into the Boolean column. Execute the following statement:

1. Mysql> INSERT INTO student(name, pass) VALUES('Miller',2);


You will get the following result:

In some cases, you need to get the result in true and false literals. In that case, you
need to execute the if() function with the select statement as follows:

1. Mysql> SELECT studentid, name, IF(pass, 'true', 'false') completed FROM student1;

It will give the following output:

MySQL Boolean Operators


MySQL also allows us to use operators with the Boolean data type. Execute the
following query to get all the pass result of table student.

1. SELECT studentid, name, pass FROM student1 WHERE pass = TRUE;

This statement returns the following output:

The above statement only returns the pass result if the value is equal to 1. We can fix it
by using the IS operator. This operator validates the value with the Boolean value. The
following statement explains this:

1. SELECT studentid, name, pass FROM student1 WHERE pass is TRUE;

After executing this statement, you will get the following result:
If you want to see the pending result, use IS FALSE or IS NOT TRUE operator as
below:

1. SELECT studentid, name, pass FROM student1 WHERE pass IS FALSE;


2.
3. OR,
4.
5. SELECT studentid, name, pass FROM student1 WHERE pass IS NOT TRUE;

You will get the following output:

SQL plus (+) operator

The SQL plus (+) operator is used to add two or more expressions or numbers.

Example:

Sample table: customer


+-----------+-------------+-------------+--------------+--------------+------
-+-------------+-------------+-------------+---------------+--------------+--
----------+
|CUST_CODE | CUST_NAME | CUST_CITY | WORKING_AREA | CUST_COUNTRY | GRADE
| OPENING_AMT | RECEIVE_AMT | PAYMENT_AMT |OUTSTANDING_AMT| PHONE_NO |
AGENT_CODE |
+-----------+-------------+-------------+--------------+--------------+------
-+-------------+-------------+-------------+---------------+--------------+--
----------+
| C00013 | Holmes | London | London | UK | 2
| 6000.00 | 5000.00 | 7000.00 | 4000.00 | BBBBBBB |
A003 |
| C00001 | Micheal | New York | New York | USA | 2
| 3000.00 | 5000.00 | 2000.00 | 6000.00 | CCCCCCC |
A008 |
| C00020 | Albert | New York | New York | USA | 3
| 5000.00 | 7000.00 | 6000.00 | 6000.00 | BBBBSBB |
A008 |
| C00025 | Ravindran | Bangalore | Bangalore | India | 2
| 5000.00 | 7000.00 | 4000.00 | 8000.00 | AVAVAVA |
A011 |
| C00024 | Cook | London | London | UK | 2
| 4000.00 | 9000.00 | 7000.00 | 6000.00 | FSDDSDF |
A006 |
| C00015 | Stuart | London | London | UK | 1
| 6000.00 | 8000.00 | 3000.00 | 11000.00 | GFSGERS |
A003 |
| C00002 | Bolt | New York | New York | USA | 3
| 5000.00 | 7000.00 | 9000.00 | 3000.00 | DDNRDRH |
A008 |
| C00018 | Fleming | Brisban | Brisban | Australia | 2
| 7000.00 | 7000.00 | 9000.00 | 5000.00 | NHBGVFC |
A005 |
| C00021 | Jacks | Brisban | Brisban | Australia | 1
| 7000.00 | 7000.00 | 7000.00 | 7000.00 | WERTGDF |
A005 |
| C00019 | Yearannaidu | Chennai | Chennai | India | 1
| 8000.00 | 7000.00 | 7000.00 | 8000.00 | ZZZZBFV |
A010 |
| C00005 | Sasikant | Mumbai | Mumbai | India | 1
| 7000.00 | 11000.00 | 7000.00 | 11000.00 | 147-25896312 |
A002 |
| C00007 | Ramanathan | Chennai | Chennai | India | 1
| 7000.00 | 11000.00 | 9000.00 | 9000.00 | GHRDWSD |
A010 |
| C00022 | Avinash | Mumbai | Mumbai | India | 2
| 7000.00 | 11000.00 | 9000.00 | 9000.00 | 113-12345678 |
A002 |
| C00004 | Winston | Brisban | Brisban | Australia | 1
| 5000.00 | 8000.00 | 7000.00 | 6000.00 | AAAAAAA |
A005 |
| C00023 | Karl | London | London | UK | 0
| 4000.00 | 6000.00 | 7000.00 | 3000.00 | AAAABAA |
A006 |
| C00006 | Shilton | Torento | Torento | Canada | 1
| 10000.00 | 7000.00 | 6000.00 | 11000.00 | DDDDDDD |
A004 |
| C00010 | Charles | Hampshair | Hampshair | UK | 3
| 6000.00 | 4000.00 | 5000.00 | 5000.00 | MMMMMMM |
A009 |
| C00017 | Srinivas | Bangalore | Bangalore | India | 2
| 8000.00 | 4000.00 | 3000.00 | 9000.00 | AAAAAAB |
A007 |
| C00012 | Steven | San Jose | San Jose | USA | 1
| 5000.00 | 7000.00 | 9000.00 | 3000.00 | KRFYGJK |
A012 |
| C00008 | Karolina | Torento | Torento | Canada | 1
| 7000.00 | 7000.00 | 9000.00 | 5000.00 | HJKORED |
A004 |
| C00003 | Martin | Torento | Torento | Canada | 2
| 8000.00 | 7000.00 | 7000.00 | 8000.00 | MJYURFD |
A004 |
| C00009 | Ramesh | Mumbai | Mumbai | India | 3
| 8000.00 | 7000.00 | 3000.00 | 12000.00 | Phone No |
A002 |
| C00014 | Rangarappa | Bangalore | Bangalore | India | 2
| 8000.00 | 11000.00 | 7000.00 | 12000.00 | AAAATGF |
A001 |
| C00016 | Venkatpati | Bangalore | Bangalore | India | 2
| 8000.00 | 11000.00 | 7000.00 | 12000.00 | JRTVFDD |
A007 |
| C00011 | Sundariya | Chennai | Chennai | India | 3
| 7000.00 | 11000.00 | 7000.00 | 11000.00 | PPHGRTS |
A010 |
+-----------+-------------+-------------+--------------+--------------+------
-+-------------+-------------+-------------+---------------+--------------+--
----------+
To get data of 'cust_name', 'opening_amt', 'receive_amt',
('opening_amt' + 'receive_amt') from the 'customer' table with following condition
-

1. sum of 'opening_amt' and 'receive_amt' is greater than 15000,

the following SQL statement can be used :


SELECT cust_name, opening_amt,

receive_amt, (opening_amt + receive_amt)

FROM customer

WHERE (opening_amt + receive_amt)>15000;

CUST_NAME OPENING_AMT RECEIVE_AMT


(OPENING_AMT+RECEIVE_AMT)
---------------------------------------- ----------- -----------
-------------------------
Sasikant 7000 11000
18000
Ramanathan 7000 11000
18000
Avinash 7000 11000
18000
Shilton 10000 7000
17000
Rangarappa 8000 11000
19000
Venkatpati 8000 11000
19000
Sundariya 7000 11000

SQL minus (-) operator


The SQL minus (-) operator is used to subtract one expression or number from
another expression or number.

Example:

To get data of 'cust_name', 'opening_amount', 'payment_amount' and


'oustanding_amount' from the 'customer' table with following condition -

1. 'outstanding_amt' - 'payment_amt' is equal to the 'receive_amt',

the following SQL statement can be used:/p>


SELECT cust_name,opening_amt, payment_amt, outstanding_amt

FROM customer

WHERE(outstanding_amt-payment_amt)=receive_amt;

Output:
CUST_NAME OPENING_AMT PAYMENT_AMT
OUTSTANDING_AMT
---------------------------------------- ----------- -----------
---------------
Stuart 6000 3000
11000

SQL multiply ( * ) operator

The SQL multiply ( * ) operator is used to multiply two or more expressions or


numbers.

Example:

Sample table: agents


+------------+----------------------+--------------------+------------+------
-----------+---------+
| AGENT_CODE | AGENT_NAME | WORKING_AREA | COMMISSION |
PHONE_NO | COUNTRY |
+------------+----------------------+--------------------+------------+------
-----------+---------+
| A007 | Ramasundar | Bangalore | 0.15 | 077-
25814763 | |
| A003 | Alex | London | 0.13 | 075-
12458969 | |
| A008 | Alford | New York | 0.12 | 044-
25874365 | |
| A011 | Ravi Kumar | Bangalore | 0.15 | 077-
45625874 | |
| A010 | Santakumar | Chennai | 0.14 | 007-
22388644 | |
| A012 | Lucida | San Jose | 0.12 | 044-
52981425 | |
| A005 | Anderson | Brisban | 0.13 | 045-
21447739 | |
| A001 | Subbarao | Bangalore | 0.14 | 077-
12346674 | |
| A002 | Mukesh | Mumbai | 0.11 | 029-
12358964 | |
| A006 | McDen | London | 0.15 | 078-
22255588 | |
| A004 | Ivan | Torento | 0.15 | 008-
22544166 | |
| A009 | Benjamin | Hampshair | 0.11 | 008-
22536178 | |
+------------+----------------------+--------------------+------------+------
-----------+----
To get data of 'agent_code', 'agent_name', 'working_area' and ('commission'*2)
from the 'agents' table with following condition -

1. two times of the default 'commission' is greater than 0.25,

the following SQL statement can be used :


SELECT agent_code, agent_name,

working_area, (commission*2)

FROM agents

WHERE (commission*2)>0.25;

Copy
Output:
AGENT_ AGENT_NAME WORKING_AREA
A003 Alex London
.26
A001 Subbarao Bangalore
.28
A007 Ramasundar Bangalore
.3
A011 Ravi Kumar Bangalore
.3
A010 Santakumar Chennai
.28
A005 Anderson Brisban
.26
A006 McDen London
.3
A004 Ivan Torento

SQL divide ( / ) operator

The SQL divide ( / ) operator is used to divide one expressions or numbers by


another.

Example:

To get data of 'cust_name', 'opening_amt', 'receive_amt', 'outstanding_amt' and


('receive_amt'*5/ 100) as a column heading 'commission' from the customer
table with following condition -

1. 'outstanding_amt' is less than or equal to 4000,

the following SQL statement can be used :


SELECT cust_name, opening_amt, receive_amt,

outstanding_amt, (receive_amt*5/ 100) commission

FROM customer

WHERE outstanding_amt<=4000;

Copy

Output:
CUST_NAME OPENING_AMT RECEIVE_AMT
OUTSTANDING_AMT
Holmes 6000 5000
4000 250
Bolt 5000 7000
3000 350
Karl 4000 6000
3000 300
Steven 5000 7000
3000 350

SQL modulo ( % ) operator

The SQL MODULO operator returns the remainder (an integer) of the division.
Example:

To get the modulus of a division of 150 by 7 from the DUAL table, the following
SQL statement can be used :
SELECT 150%7;

Copy

Output:

You might also like