Thanks to visit codestin.com
Credit goes to www.scribd.com

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

Arthmatic Operators

USED FOR THE INTERVIEW QUESTION IN MANY OF THE INTERVIEWS U CAN ESAILY CRACK THE ISSUE
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views13 pages

Arthmatic Operators

USED FOR THE INTERVIEW QUESTION IN MANY OF THE INTERVIEWS U CAN ESAILY CRACK THE ISSUE
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 13

cArthmatic Operators

+ addition
- substraction
% modulus
* multiplictaion
/ division

Query 1: write a query to add two numbers using addition operator

OUTPUT:

mysql> select 10000+300;


+-----------+
| 10000+300 |
+-----------+
| 10300 |
+-----------+
1 row in set (0.01 sec)

Query 2: write a query subtract two numbers using subtraction operator

OUTPUT:

mysql> select 2000-10;


+---------+
| 2000-10 |
+---------+
| 1990 |
+---------+
1 row in set (0.01 sec)

Query 3: write a query multipy two numbers using multiplication operator

OUTPUT:

mysql> select 3000*21;


+---------+
| 3000*21 |
+---------+
| 63000 |
+---------+
1 row in set (0.00 sec)

mysql>

Query 4:Write a query divide two numbers using division operator

OUTPUT:

mysql> select 800/4;


+----------+
| 800/4 |
+----------+
| 200.0000 |
+----------+
1 row in set (0.00 sec)
Query 5:write a query modulus two numbers using modulus operator

output:

mysql> select 432%5;


+-------+
| 432%5 |
+-------+
| 2 |
+-------+
1 row in set (0.00 sec)

using arthmatic operators:

mysql> select * from department;


+---------+-------------------+-------+
| dept_id | dept_name | dm_id |
+---------+-------------------+-------+
| 10 | sales | 1 |
| 20 | executive | 2 |
| 30 | shipping | 3 |
| 40 | digital marketing | 4 |
| 50 | It | 5 |
| 60 | account | 6 |
| 70 | HR | 7 |
+---------+-------------------+-------+

mysql> select * from employee;


+------+-------------+------------+----------------------------+------------
+----------+---------+
| e_id | e_firstname | e_lastname | e_email | e_doj |
e_salary | dept_id |
+------+-------------+------------+----------------------------+------------
+----------+---------+
| 1 | vanaja | dhandu | [email protected] | 1997-12-03 |
99000 | 50 |
| 2 | sirisha | gandham | [email protected] | 2002-09-04 |
76543 | 70 |
| 3 | pragna | raj | [email protected] | 2000-07-07 |
98765 | 70 |
| 4 | pranav | beeman | [email protected] | 2005-03-02 |
53765 | 30 |
| 5 | danush | gandam | [email protected] | 2002-12-11 |
74872 | 20 |
| 6 | vishnu | dhandu | [email protected] | 2009-06-20 |
38231 | 20 |
+------+-------------+------------+----------------------------+------------
+----------+---------+

QUERY:

Display firstname,last name and salary of all the employees by adding 3200 to the
salary of all the employee?

mysql> select e_firstname,e_lastname ,e_salary+3200 as e_sal from employee;


+-------------+------------+--------+
| e_firstname | e_lastname | e_sal |
+-------------+------------+--------+
| vanaja | dhandu | 102200 |
| sirisha | gandham | 79743 |
| pragna | raj | 101965 |
| pranav | beeman | 56965 |
| danush | gandam | 78072 |
| vishnu | dhandu | 41431 |
+-------------+------------+--------+
6 rows in set (0.00 sec)

Query 2::

display first name,last name and salary of all the employees adding dept_id to the
salary of all the employees?

mysql> select e_firstname,e_lastname,e_salary+dept_id as salary from employee;


+-------------+------------+--------+
| e_firstname | e_lastname | salary |
+-------------+------------+--------+
| vanaja | dhandu | 99050 |
| sirisha | gandham | 76613 |
| pragna | raj | 98835 |
| pranav | beeman | 53795 |
| danush | gandam | 74892 |
| vishnu | dhandu | 38251 |
+-------------+------------+--------+
6 rows in set (0.00 sec)

Query 3:
Display first name,last name and salary of all the employees by subtracting 1000 to
the salary of all the employees

mysql> select e_firstname,e_lastname,e_salary-1000 as salary from employee;


+-------------+------------+--------+
| e_firstname | e_lastname | salary |
+-------------+------------+--------+
| vanaja | dhandu | 98000 |
| sirisha | gandham | 75543 |
| pragna | raj | 97765 |
| pranav | beeman | 52765 |
| danush | gandam | 73872 |
| vishnu | dhandu | 37231 |
+-------------+------------+--------+
6 rows in set (0.01 sec)

Query 4:
Display firstname ,lastname and annual salary of all the employees?

mysql> select e_firstname as fn,e_lastname as ln,e_salary*12 as salary from


employee;
+---------+---------+---------+
| fn | ln | salary |
+---------+---------+---------+
| vanaja | dhandu | 1188000 |
| sirisha | gandham | 918516 |
| pragna | raj | 1185180 |
| pranav | beeman | 645180 |
| danush | gandam | 898464 |
| vishnu | dhandu | 458772 |
+---------+---------+---------+
6 rows in set (0.00 sec)

Query 5:

Display first name,last name and annual salry of all the employees with dept_id as
20

mysql> select e_firstname,e_lastname,e_salary*12 as annualsalary


-> from employee
-> where dept_id=20;
+-------------+------------+--------------+
| e_firstname | e_lastname | annualsalary |
+-------------+------------+--------------+
| danush | gandam | 898464 |
| vishnu | dhandu | 458772 |
+-------------+------------+--------------+
2 rows in set (0.00 sec)

Query 6:
diaplay firstname,lastname and half year sakary from all the employees?

mysql> select e_firstname,e_lastname,e_salary*6 as half_year_salary from employee;


+-------------+------------+------------------+
| e_firstname | e_lastname | half_year_salary |
+-------------+------------+------------------+
| vanaja | dhandu | 594000 |
| sirisha | gandham | 459258 |
| pragna | raj | 592590 |
| pranav | beeman | 322590 |
| danush | gandam | 449232 |
| vishnu | dhandu | 229386 |
+-------------+------------+------------------+
6 rows in set (0.00 sec)

or

output:

mysql> select e_firstname,e_lastname,e_salary*12/2 as half_year_salary from


employee;
+-------------+------------+------------------+
| e_firstname | e_lastname | half_year_salary |
+-------------+------------+------------------+
| vanaja | dhandu | 594000.0000 |
| sirisha | gandham | 459258.0000 |
| pragna | raj | 592590.0000 |
| pranav | beeman | 322590.0000 |
| danush | gandam | 449232.0000 |
| vishnu | dhandu | 229386.0000 |
+-------------+------------+------------------+
6 rows in set (0.00 sec)

Query 7:

Display firstname,lastname and annual salary ,half yearly salary,querterly salary


of all employees

mysql>select e_firstname,e_lastname,(e_salary*12) as annual_Salary ,(e_salary*12/2)


as half_yearly,(e_salary*12/3) as querterly from employee;

+-------------+------------+---------------+-------------+-------------+
| e_firstname | e_lastname | annual_Salary | half_yearly | querterly |
+-------------+------------+---------------+-------------+-------------+
| vanaja | dhandu | 1188000 | 594000.0000 | 396000.0000 |
| sirisha | gandham | 918516 | 459258.0000 | 306172.0000 |
| pragna | raj | 1185180 | 592590.0000 | 395060.0000 |
| pranav | beeman | 645180 | 322590.0000 | 215060.0000 |
| danush | gandam | 898464 | 449232.0000 | 299488.0000 |
| vishnu | dhandu | 458772 | 229386.0000 | 152924.0000 |
+-------------+------------+---------------+-------------+-------------+
6 rows in set (0.00 sec)

Query 8:

Display firstname,lastname and salary of all the employees where salary is not
divisible (reminder is 0) by 3;

mysql> select E_firstname,e_lastname,e_salary


-> from
-> employee
-> where e_salary%3!=0;
+-------------+------------+----------+
| E_firstname | e_lastname | e_salary |
+-------------+------------+----------+
| sirisha | gandham | 76543 |
| pragna | raj | 98765 |
| pranav | beeman | 53765 |
| danush | gandam | 74872 |
| vishnu | dhandu | 38231 |
+-------------+------------+----------+
5 rows in set (0.00 sec)

Query 9:diaplay firstname,lastname and salary of all employees with salary


increment by 10%?

mysql> select e_firstname,e_lastname,e_salary+(e_salary*10/100) as incrementsalary


from employee;
+-------------+------------+-----------------+
| e_firstname | e_lastname | incrementsalary |
+-------------+------------+-----------------+
| vanaja | dhandu | 108900.0000 |
| sirisha | gandham | 84197.3000 |
| pragna | raj | 108641.5000 |
| pranav | beeman | 59141.5000 |
| danush | gandam | 82359.2000 |
| vishnu | dhandu | 42054.1000 |
+-------------+------------+-----------------+
6 rows in set (0.00 sec)

BETWEEN AND
OPERATOR

Query 10:

display firstname and lastname from all the employees where salary is in the range
40000 to 70000

mysql> select e_firstname,e_lastname,e_salary


-> from employee
-> where e_salary>=40000 and e_salary<=70000;
+-------------+------------+----------+
| e_firstname | e_lastname | e_salary |
+-------------+------------+----------+
| pranav | beeman | 53765 |
+-------------+------------+----------+
1 row in set (0.00 sec)

Query 11:

write a query to display the firstname, lastnam of all the employees where hire
date is in the range of 2018-01-01 to 2020-01-01??

mysql> select e_firstname,e_lastname,e_doj


-> from employee
-> where e_doj
-> between
-> '2002-01-01' and '2005-01-01';
+-------------+------------+------------+
| e_firstname | e_lastname | e_doj |
+-------------+------------+------------+
| sirisha | gandham | 2002-09-04 |
| danush | gandam | 2002-12-11 |
+-------------+------------+------------+
2 rows in set (0.01 sec)

query 12:
write a query to display the firstname,lastname of all the employees where first
letter of first nae is in between P and V?

mysql> select e_firstname,e_lastname


-> from
-> employee
-> where e_firstname
-> between 'p' and 'v';
+-------------+------------+
| e_firstname | e_lastname |
+-------------+------------+
| sirisha | gandham |
| pragna | raj |
| pranav | beeman |
+-------------+------------+
3 rows in set (0.00 sec)

QUERY 13:
write a query firstname,salary of all employee where salary is not in the range of
40000 to 70000?

mysql> select e_firstname,e_salary


-> from employee
-> where e_salary
-> not between 40000 and 70000
-> ;
+-------------+----------+
| e_firstname | e_salary |
+-------------+----------+
| vanaja | 99000 |
| sirisha | 76543 |
| pragna | 98765 |
| danush | 74872 |
| vishnu | 38231 |
+-------------+----------+
IN operator

Query 14:
write a query to display the first name,salary of all the employees where salary is
equal to 32000,56000,78000?

mysql> select e_firstname,e_salary


-> from employee
-> where e_salary
-> in(32000,56000,78000);
Empty set (0.00 sec)

Query 14:
write a query to display the first name,salary of all the employees where salary is
equal to 76543,32000,99000?

mysql> select e_firstname ,e_salary


-> from employee
-> where e_salary
-> in(76543,32000,99000);
+-------------+----------+
| e_firstname | e_salary |
+-------------+----------+
| vanaja | 99000 |
| sirisha | 76543 |
+-------------+----------+
2 rows in set (0.00 sec)

mysql>
Query 15;
write a query to display the firstname,salary of all the employees where salary is
not equal to 76543,32000,99000?

mysql> select e_firstname,e_salary


-> from employee
-> where e_salary
-> not in( 76543,32000,99000);
+-------------+----------+
| e_firstname | e_salary |
+-------------+----------+
| pragna | 98765 |
| pranav | 53765 |
| danush | 74872 |
| vishnu | 38231 |
+-------------+----------+
4 rows in set (0.00 sec)

is null operator

Query 16:
write a query to display all the employee with dept_id is null:

mysql> select dept_id


-> from employee
-> where dept_id
-> is null

Empty set (0.00 sec)

Query 17:

write a query to display firstname and salary of all the employee with dept_id is
not null?

mysql> select e_firstname,e_salary


-> from employee
-> where dept_id
-> is not null;
+-------------+----------+
| e_firstname | e_salary |
+-------------+----------+
| danush | 74872 |
| vishnu | 38231 |
| pranav | 53765 |
| vanaja | 99000 |
| sirisha | 76543 |
| pragna | 98765 |
+-------------+----------+
6 rows in set (0.00 sec)

LIKE OPERATOR
QUERY 18:

display fn and ln of the employee whose fn starts with va?

mysql> select e_firstname


-> from employee
-> where
-> e_firstname
-> like 'va%';
+-------------+
| e_firstname |
+-------------+
| vanaja |
+-------------+
1 row in set (0.00 sec)

QUERY 19:

write a query to diplay the fn and ln of the employee whose firstname has the
second character 'h'?

mysql> select e_firstname


-> from employee
-> where e_firstname
-> like '_i%';
+-------------+
| e_firstname |
+-------------+
| sirisha |
| vishnu |
+-------------+
2 rows in set (0.00 sec)

Query 20:

write a query to display first name and last name of the employe whose last name
ends with 'u'

mysql> select e_firstname,e_lastname


-> from employee
-> where e_lastname
-> like '%u'
-> ;
+-------------+------------+
| e_firstname | e_lastname |
+-------------+------------+
| vanaja | dhandu |
| vishnu | dhandu |
+-------------+------------+
2 rows in set (0.00 sec)
Query 21:

write a quey to display first name and last name of the employee whose first name
begins with '' and at least 3 characters in length?

mysql> select e_firstname,e_lastname


-> from employee
-> where e_firstname
-> like 'd__%';
+-------------+------------+
| e_firstname | e_lastname |
+-------------+------------+
| danush | gandam |
+-------------+------------+
1 row in set (0.00 sec)

Query 22:
write a query to display firstname and last name of the employee whose first name
begins contains 'a'?

mysql> select e_firstname,e_lastname


-> from employee
-> where e_firstname
-> like '%a%';
+-------------+------------+
| e_firstname | e_lastname |
+-------------+------------+
| vanaja | dhandu |
| sirisha | gandham |
| pragna | raj |
| pranav | beeman |
| danush | gandam |
+-------------+------------+
5 rows in set (0.00 sec)

Query 23:

write a query to display first name and last name of the employee whose last name
has third charecter 'l'?
mysql> select e_firstname ,e_lastname
-> from employee
-> where e_firstname
-> like '%__a%a';
+-------------+------------+
| e_firstname | e_lastname |
+-------------+------------+
| vanaja | dhandu |
| pragna | raj |
+-------------+------------+
2 rows in set (0.00 sec)

Query 24:

write a query to display first name and last name of the employee whose firstname
has two consecutive 'll'?
mysql> select e_firstname,e_lastname
-> from employee
-> where e_firstname
-> like '%ll%';
+-------------+------------+
| e_firstname | e_lastname |
+-------------+------------+
| lalli | sahasra |
+-------------+------------+
1 row in set (0.00 sec)

QUERY 25:
WRITE A QUERY TO DISPLAY FIRST NAME AND LAST NAME OF THE EMPLOYEE WHOSE FIRST NAME
IS 6 CHARACTERS LONG HAS THIRD CHARACTER 'N'?

mysql> SELECT E_FIRSTNAME,E_LASTNAME


-> FROM EMPLOYEE
-> WHERE E_FIRSTNAME
-> LIKE '__N___';
+-------------+------------+
| E_FIRSTNAME | E_LASTNAME |
+-------------+------------+
| vanaja | dhandu |
| danush | gandam |
+-------------+------------+
2 rows in set (0.00 sec)

Query 26:

write a query to display firstname , lastname and salary of the employee who are
earning 5 digit salary

mysql> select e_firstname,e_lastname


-> from employee
-> where e_salary
-> like '_____';
+-------------+------------+
| e_firstname | e_lastname |
+-------------+------------+
| vanaja | dhandu |
| sirisha | gandham |
| pragna | raj |
| pranav | beeman |
| danush | gandam |
| vishnu | dhandu |
| lalli | sahasra |
+-------------+------------+
7 rows in set (0.00 sec)

Query 27:

write a query to display firstname,lastname and salary of the employee whose salary
starts with 4
mysql> select e_firstname,e_lastname,e_salary
-> from employee
-> where e_salary
-> like '4%';
+-------------+------------+----------+
| e_firstname | e_lastname | e_salary |
+-------------+------------+----------+
| lalli | sahasra | 43432 |
+-------------+------------+----------+
1 row in set (0.00 sec)

Query 28:

write a query to display firstname ,lastname and hire date of the employee who
arehired in the yera of 2000;

mysql> select e_firstname ,e_lastname,e_doj


-> from employee
-> where e_doj
-> like '2000%';
+-------------+------------+------------+
| e_firstname | e_lastname | e_doj |
+-------------+------------+------------+
| pragna | raj | 2000-07-07 |
+-------------+------------+------------+
1 row in set (0.00 sec)

query 29:

write a query to display first name,e_lastname and hire date of the employee who
are hired in the month of february
?

mysql> select e_firstname ,e_lastname,e_doj


-> from employee
-> where e_doj
-> like '____-12%';
+-------------+------------+------------+
| e_firstname | e_lastname | e_doj |
+-------------+------------+------------+
| vanaja | dhandu | 1997-12-03 |
| danush | gandam | 2002-12-11 |
+-------------+------------+------------+
2 rows in set (0.00 sec)

Query 30;

write a query to display firstname , lastnaem and hire date of the employee whose
salary has last 3 digit as '0's

mysql> select e_firstname,e_lastname,e_salary


-> from employee
-> where e_Salary
-> like '%000';
+-------------+------------+----------+
| e_firstname | e_lastname | e_salary |
+-------------+------------+----------+
| vanaja | dhandu | 99000 |
+-------------+------------+----------+
1 row in set (0.00 sec)

You might also like