SQL
SQL
--1) Retrieve names of all managers of the department along with their number of
female dependents.
--2) Retrieve names of all managers of the department who have more than one
dependent along with their number of dependents.
--3) For each project for which more than one employee works retrieve its name and
number of employee working.
--4) Make a list of employee name whose address is in Vidyanagar and who works on
project productx along with number of dependents.
--5) Retrieve names of all employee who work for the department that controls more
than one project.
select fname,mname,lname
from Employee,Department,Project
where dnum=dno and dnum=deptno
group by Dnum,fname,mname,lname
having count(*)>1;
--6) Retrieve ssn, name and dept. name of all the employees who work on any project
controlled by his own department.
--7) For each department that has more than one location retrieve its name and
number of project controlled by that department.
--8) For each project controlled by Research department for which more than one
employee is working Retrieve name of that project and number of employees working
for it.
--10) For each department which controls more than one project retrieve department
name along with number of employees working in that department.
--11) For each department which do not control any project retrieve department name
along with number of employees working in that department.
--12) For each female employee who works for ‘Admin’ department retrieve first name
in ascending order along with number of projects the employee works on.
select fname,count(*)
from Employee,Department,Workson
where dnum=dno and ssn=essn and dname='Admin' and Employee.sex='f'
group by ssn,fname
order by count(*);
--13) Retrieve names of all employees who work on at least one project controlled
by ‘Head quarters’ department.
select fname,mname,lname
from Employee,Project,Department,Workson
where dnum=deptno and ssn=essn and pnum=pno and dname='Head quarters';
--14) Retrieve name and ssn of all employees born after 1950 and having no
dependents.
select fname,mname,lname,ssn
from Employee
where ssn not in (select essn
from Dependent) and extract(year from dob) > 1950
order by ssn;
--15) Retrieve names of all department managers who have at least one dependent.
select fname,mname,lname
from Employee,Dependent
where ssn in (select mgrssn
from Department) and ssn=essn
group by ssn,fname,mname,lname;
--16) Retrieve names of all ‘CS’ department employees who have more than one female
dependents.
select fname,mname,lname
from Employee,Department,Dependent
where dnum=dno and ssn=essn and dname='CS' and Dependent.sex='f'
group by ssn,fname,mname,lname
having count(*)>1;