Professional Documents
Culture Documents
use EMPLOYEE;
Database changed
show tables;
Empty set (0.001 sec)
desc Employee;
+---------------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------------+----------+------+-----+---------+-------+
| Employee_Name | char(20) | NO | PRI | NULL | |
| Street | char(20) | YES | | NULL | |
| City | char(20) | YES | | NULL | |
+---------------+----------+------+-----+---------+-------+
3 rows in set (0.005 sec)
DESC Works;
+---------------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------------+----------+------+-----+---------+-------+
| Employee_Name | char(20) | NO | PRI | NULL | |
| Company_Name | char(25) | YES | | NULL | |
| Salary | int(11) | YES | | NULL | |
+---------------+----------+------+-----+---------+-------+
3 rows in set (0.005 sec)
desc Company;
+--------------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------------+----------+------+-----+---------+-------+
| Company_Name | char(25) | NO | PRI | NULL | |
| City | char(20) | YES | | NULL | |
+--------------+----------+------+-----+---------+-------+
2 rows in set (0.005 sec)
desc Manages;
+---------------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------------+----------+------+-----+---------+-------+
| Employee_Name | char(20) | NO | PRI | NULL | |
| Manager_Name | char(20) | YES | | NULL | |
+---------------+----------+------+-----+---------+-------+
2 rows in set (0.004 sec)
(a.)
select Employee_Name from Works where Company_Name="First_Bank_Corporation";
+---------------+
| Employee_Name |
+---------------+
| Franklin_Wong |
| James_Borg |
+---------------+
2 rows in set (0.011 sec)
(b.)
select Employee.Employee_Name,City from Employee,Works where
Works.Company_Name="First_Bank_Corporation" AND
Employee.Employee_Name=Works.Employee_Name;
+---------------+-----------+
| Employee_Name | City |
+---------------+-----------+
| Franklin_Wong | Noida |
| James_Borg | New_Delhi |
+---------------+-----------+
2 rows in set (0.014 sec)
(c.)
select * from Employee where Employee_Name IN(select Employee_Name from Works
where Company_Name="First_Bank_Corporation" AND Salary>10000);
+---------------+--------+-----------+
| Employee_Name | Street | City |
+---------------+--------+-----------+
| Franklin_Wong | 11/120 | Noida |
| James_Borg | 8/24 | New_Delhi |
+---------------+--------+-----------+
2 rows in set (0.020 sec)
(d.)
select Employee.Employee_Name from Employee,Works,Company where
Employee.Employee_Name=Works.Employee_Name AND Employee.City=Company.City AND
Works.Company_Name=Company.Company_Name;
+---------------+
| Employee_Name |
+---------------+
| James_Borg |
+---------------+
1 row in set (0.002 sec)
(f.)
select Employee_Name from Works where Company_Name<>"First_Bank_Corporation";
+---------------+
| Employee_Name |
+---------------+
| John_Smith |
| Jones |
+---------------+
2 rows in set (0.002 sec)
(g.)
select Employee_Name from Works where Salary>ALL (select Salary from Works where
Company_Name="Small_Bank_Corporation");
Empty set (0.002 sec)
(i.)
select Employee_Name from Works where Salary> (select AVG(Salary) from Works
where Works.Company_Name=Works.Company_Name);
+---------------+
| Employee_Name |
+---------------+
| John_Smith |
| Jones |
+---------------+
2 rows in set (0.016 sec)
(j.)
select Company_Name from Works GROUP BY Company_Name HAVING count(DISTINCT
Employee_Name)>= ALL (select COUNT(DISTINCT Employee_Name) from Works GROUP BY
Company_Name);
+------------------------+
| Company_Name |
+------------------------+
| First_Bank_Corporation |
+------------------------+
1 row in set (0.019 sec)
(k.)
select Company_Name from Works GROUP BY Company_Name HAVING SUM(Salary) <=ALL
(select SUM(Salary) from Works GROUP BY Company_Name);
+-----------------------+
| Company_Name |
+-----------------------+
| Insurance_Corporation |
+-----------------------+
1 row in set (0.063 sec)
(l.)
select Company_Name from Works GROUP BY Company_Name HAVING AVG(Salary) > (select
AVG(Salary) from Works where Company_Name="First_Bank_Corporation");
+------------------------+
| Company_Name |
+------------------------+
| Insurance_Corporation |
| Small_Bank_Corporation |
+------------------------+
2 rows in set (0.009 sec)
(m.)
UPDATE Employee SET City="Newton" where Employee_Name="Jones";
Query OK, 1 row affected (0.022 sec)
Rows matched: 1 Changed: 1 Warnings: 0
(n.)
UPDATE Works SET Salary=Salary*1.1 where Company_Name="First_Bank_Corporation";
Query OK, 2 rows affected (0.010 sec)
Rows matched: 2 Changed: 2 Warnings: 0
(p.)
UPDATE Works SET Works.Salary=Works.Salary*1.03 where Works.Employee_Name
IN(select Manager_Name from Manages) AND Works.Query OK, 0 rows affected (0.001
sec)ame="First_Bank_Corporation";
Rows matched: 0 Changed: 0 Warnings: 0
(q.)
select * from Works;
+---------------+------------------------+--------+
| Employee_Name | Company_Name | Salary |
+---------------+------------------------+--------+
| Franklin_Wong | First_Bank_Corporation | 16500 |
| James_Borg | First_Bank_Corporation | 27500 |
| John_Smith | Small_Bank_Corporation | 45000 |
| Jones | Insurance_Corporation | 30000 |
+---------------+------------------------+--------+
4 rows in set (0.018 sec)