0% found this document useful (0 votes)
28 views5 pages

Ass 2 A

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

Ass 2 A

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

ASSIGNMENT - 2A

Name : Sarthak Nere


Branch : Comp
Batch : T2
RollNo : 46

Displaying both the tables :-


select * from Employee;
+------+--------+--------+--------+-----------+
| ID | Name | City | Salary | Comission |
+------+--------+--------+--------+-----------+
| 1 | Amit | Pune | 35000 | 5000 |
| 2 | Sneha | Pune | 25000 | 0|
| 3 | Savita | Nashik | 28000 | 2000 |
| 4 | Pooja | Mumbai | 19000 | 0|
| 5 | Sagar | Mumbai | 25000 | 3000 |
+------+--------+--------+--------+-----------+
5 rows in set (0.00 sec)

mysql> select *from Project;


+------+--------+
| PrNo | City |
+------+--------+
| 1 | Mumbai |
| 2 | Pune |
| 3 | Nashik |
+------+--------+
3 rows in set (0.00 sec)

Solving Queries:-
1.What is maximum and minimum salary?

mysql> select max(Salary) from Employee;


+-------------+
| max(Salary) |
+-------------+
| 35000 |
+-------------+
1 row in set (0.00 sec)

mysql> select min(Salary) from Employee;


+-------------+
| min(Salary) |
+-------------+
| 19000 |
+-------------+
1 row in set (0.01 sec)
2.Display the content of employee table according to the ascending order of
salary amount.

mysql> select * from Employee


-> order by Salary asc;
+------+--------+--------+--------+-----------+
| ID | Name | City | Salary | Comission |
+------+--------+--------+--------+-----------+
| 4 | Pooja | Mumbai | 19000 | 0|
| 2 | Sneha | Pune | 25000 | 0|
| 5 | Sagar | Mumbai | 25000 | 3000 |
| 3 | Savita | Nashik | 28000 | 2000 |
| 1 | Amit | Pune | 35000 | 5000 |
+------+--------+--------+--------+-----------+
5 rows in set (0.01 sec)

3.Find the name of employee who lived in Nasik or Pune city.

mysql> select Name from Employee


-> where City = 'Nashik' or City = 'Pune';
+--------+
| Name |
+--------+
| Amit |
| Sneha |
| Savita |
+--------+
3 rows in set (0.02 sec)

4.Find the name of employees who does not get commission.

mysql> select Name from Employee


-> where Comission = 0;
+-------+
| Name |
+-------+
| Sneha |
| Pooja |
+-------+
2 rows in set (0.00 sec)

5.Find different locations from where employees belong to and also change the
city of Amit to Nashik.

mysql> select City from Employee;


+--------+
| City |
+--------+
| Pune |
| Pune |
| Nashik |
| Mumbai |
| Mumbai |
+--------+
5 rows in set (0.00 sec)

mysql> update Employee


-> set City = 'Nashik'
-> where ID = 1;
Query OK, 1 row affected (0.04 sec)
Rows matched: 1 Changed: 1 Warnings: 0

mysql> select * from Employee;


+------+--------+--------+--------+-----------+
| ID | Name | City | Salary | Comission |
+------+--------+--------+--------+-----------+
| 1 | Amit | Nashik | 35000 | 5000 |
| 2 | Sneha | Pune | 25000 | 0|
| 3 | Savita | Nashik | 28000 | 2000 |
| 4 | Pooja | Mumbai | 19000 | 0|
| 5 | Sagar | Mumbai | 25000 | 3000 |
+------+--------+--------+--------+-----------+
5 rows in set (0.00 sec)

6.Find the information of employees whose name starts with ‘A’.

mysql> select * from Employee


-> where Name like 'A%';
+------+------+--------+--------+-----------+
| ID | Name | City | Salary | Comission |
+------+------+--------+--------+-----------+
| 1 | Amit | Nashik | 35000 | 5000 |
+------+------+--------+--------+-----------+
1 row in set (0.00 sec)

7.Find the count of staff from Mumbai.

mysql> select count(City)


-> from Employee
-> where City = 'Mumbai';
+-------------+
| count(City) |
+-------------+
| 2|
+-------------+
1 row in set (0.00 sec)

8.Find the count of staff from each city

mysql> select count(City) from Employee where City = 'Nashik';


+-------------+
| count(City) |
+-------------+
| 2|
+-------------+
1 row in set (0.00 sec)

mysql> select count(City) from Employee where City = 'Pune';


+-------------+
| count(City) |
+-------------+
| 1|
+-------------+
1 row in set (0.00 sec)

9.Find the address from where employees are belonging as well as where
projects are going on.

mysql> select * from Employee cross join Project on Employee.City = Project.City;


+------+--------+--------+--------+-----------+------+--------+
| ID | Name | City | Salary | Comission | PrNo | City |
+------+--------+--------+--------+-----------+------+--------+
| 2 | Sneha | Pune | 25000 | 0 | 2 | Pune |
| 3 | Savita | Nashik | 28000 | 2000 | 3 | Nashik |
| 4 | Pooja | Mumbai | 19000 | 0 | 1 | Mumbai |
| 5 | Sagar | Mumbai | 25000 | 3000 | 1 | Mumbai |
+------+--------+--------+--------+-----------+------+--------+
4 rows in set (0.00 sec)

10.Find city wise minimum salary.

mysql> select min(Salary) from Employee where City='Mumbai';


+-------------+
| min(Salary) |
+-------------+
| 19000 |
+-------------+
1 row in set (0.00 sec)

mysql> select min(Salary) from Employee where City='Pune';


+-------------+
| min(Salary) |
+-------------+
| 25000 |
+-------------+
1 row in set (0.00 sec)

mysql> select min(Salary) from Employee where City='Nashik';


+-------------+
| min(Salary) |
+-------------+
| 28000 |
+-------------+
1 row in set (0.00 sec)
11.Find city wise maximum salary having maximum salary greater than 26000

mysql> select max(Salary) from Employee where City='Nashik' and Salary > 26000;
+-------------+
| max(Salary) |
+-------------+
| 35000 |
+-------------+
1 row in set (0.00 sec)

mysql> select max(Salary) from Employee where City='Pune' and Salary > 26000;
+-------------+
| max(Salary) |
+-------------+
| NULL |
+-------------+
1 row in set (0.00 sec)

mysql> select max(Salary) from Employee where City='Mumbai' and Salary > 26000;
+-------------+
| max(Salary) |
+-------------+
| NULL |
+-------------+
1 row in set (0.00 sec)

12.Delete the employee who is having salary greater than 30,000.

mysql> delete from Employee


-> where Salary > 30000;
Query OK, 1 row affected (0.05 sec)

mysql> select * from Employee


-> ;
+------+--------+--------+--------+-----------+
| ID | Name | City | Salary | Comission |
+------+--------+--------+--------+-----------+
| 2 | Sneha | Pune | 25000 | 0|
| 3 | Savita | Nashik | 28000 | 2000 |
| 4 | Pooja | Mumbai | 19000 | 0|
| 5 | Sagar | Mumbai | 25000 | 3000 |
+------+--------+--------+--------+-----------+
4 rows in set (0.00 sec)

You might also like