Practical 04
Tables:
1) Project:(pid(foreign_key),pname,pDescription,pCategory)
2) Department:(did,pid(foreign_key),dname(primary_key))
3) Employee:e(eid(primary),ename,salary,did,pid(foreign),dname(foreign))
1)select * from project;
+-----+--------------+---------------+--------------+
| pid | project_desc | project_categ | project_name |
+-----+--------------+---------------+--------------+
| 11 | AI_based | software | XYZ |
| 22 | ML_based | hardware | ABC |
| 33 | DSA_based | CAD | PQR |
| 44 | CLOUD_based | software | MNP |
2) select * from department;
+------+------+------------+
| did | pid | dept_name |
+------+------+------------+
| 44 | 44 | Production |
| 11 | 11 | AI |
| 22 | 22 | CS |
| 33 | 33 | IT |
3) select * from employee;
+-----+-------+--------+------+------+------------+
| eid | ename | salary | did | pid | dept_name |
+-----+-------+--------+------+------+------------+
| 101 | Maddy | 20000 | 22 | 22 | AI |
| 102 | sandy | 30000 | 33 | 33 | Production |
| 103 | Candy | 40000 | 44 | 44 | CS |
| 104 | Andy | 50000 | 11 | 11 | IT |
Query 1] Display details of emp working on production dept
select ename,salary,did,pid from employee where dept_name='Production';
+-------+--------+------+------+
| ename | salary | did | pid |
+-------+--------+------+------+
| sandy | 30000 | 33 | 33 |
+-------+--------+------+------+
Query 2]Display details of emp;
Ans: select * from employee;
Query 3]Display name of emp whose start letter is ‘a’
select ename from employee where ename like 'a%';
+-------+
| ename |
+-------+
| Andy |
Query 4]arrange the name of project employee department in alphabetical order
select project_name,ename,dept_name from project join employee on
project.pid=employee.pid order by project_name,ename,dept_name;
+--------------+-------+------------+
| project_name | ename | dept_name |
+--------------+-------+------------+
| ABC | Maddy | AI |
| MNP | Candy | CS |
| PQR | sandy | Production |
| XYZ | Andy | IT |
Query 5]display name of employee who are not working for production
department and whose department ID is 44
select ename from employee where did=44 or dept_name!='Production';
+-------+
| ename |
+-------+
| Maddy |
| Candy |
| Andy |
Query 6]list of project where employee working on XYZ project
select * from project where project_name='XYZ';
+-----+--------------+---------------+--------------+
| pid | project_desc | project_categ | project_name |
+-----+--------------+---------------+--------------+
| 11 | AI_based | software | XYZ |
Query 7] list of employee with minimum , maximum salary according to
department name
select dept_name,min(salary),max(salary) from employee group by dept_name;
+------------+-------------+-------------+
| dept_name | min(salary) | max(salary) |
+------------+-------------+-------------+
| AI | 20000 | 20000 |
| CS | 40000 | 40000 |
| IT | 50000 | 50000 |
| Production | 30000 | 30000 |
Query 8]display project name whose category belonging in either hardware or
software
select project_name from project where project_categ='hardware' or project_categ=
'software';
+--------------+
| project_name |
+--------------+
| XYZ |
| ABC |
| MNP |