Employee Queries
Employee Queries
select fname from employee e where not exists (select fname from employee a
where a.ssn=e.superssn);
11. Retrieve the name and address of all employees who work for the
'Research' Department
select fname,minit,lname from employee,department where
dname="research" and department.dnumber=employee.dno;
12. For every project located in 'Stafford', list the project number, the
controlling department number, and the department manager's last
name, address, and birthdate.
Select pnumber, dnum, lname, address,bdate from project, department,
employee where plocation="Stafford" and dnum=dnumber and mgrssn=ssn;
13. For each employee, retrieve the employee's name, and the name of
his or her immediate supervisor.
select f.fname as employee,e.fname as supervisor from employee e,employee f
where e.ssn=f.superssn ;
14. Find the maximum salary, the minimum salary, and the average
salary among all employees.
FROM EMPLOYEE;
15. Find the maximum salary, the minimum salary, and the average
salary among employees who work for the 'Research' department.
SELECT MAX (SALARY), MIN(SALARY), AVG(SALARY)
FROM EMPLOYEE
Make a list of all project numbers for projects that involve an employee
whose last name is 'Smith' as a worker or as a manager of the department
that controls the project.
Make a list of all project numbers for projects that involve an employee
whose last name is 'wong' as a worker or as a manager of the department
that controls the project.
(SELECT PNUMBER
UNION
(SELECT PNUMBER
Retrieve the name of each employee who has a dependent with the same
first name and same sex as the employee
alternate:
Retrieve the social security numbers of all employees who work on project
number 1, 2 or 3
SELECT DISTINCT ESSN
FROM WORKS_ON
WHERE PNO IN (1,2,3);
For each project, retrieve the project number, the project name, and the
number of employees who work on that
Project
SELECT PNUMBER, PNAME, COUNT (*)
FROM PROJECT, WORKS_ON
WHERE PNUMBER = PNO
GROUP BY PNUMBER, PNAME;
For each project on which more than two employees work, retrieve the
project number, the project name, and the
number of employees who work on the project
SELECT PNUMBER, PNAME, COUNT (*)
FROM PROJECT, WORKS_ON
WHERE PNUMBER = PNO
GROUP BY PNUMBER, PNAME
HAVING COUNT (*) > 2;
For each project, retrieve the project number, the project name, and the
number of employees from department 5 who
work on the project
SELECT PNUMBER, PNAME, COUNT (*)
FROM PROJECT, WORKS_ON, EMPLOYEE
WHERE PNUMBER = PNO AND SSN = ESSN AND DNO = 5
GROUP BY PNUMBER, PNAME;
Retrieve the names of all employees who have two or more dependents
15 Retrieve a list of employees and the projects they are working on,
ordered by department and, within each department, ordered alphabetically by last name,
first name
Retrieve the name of each employee who has a dependent with the
28A For each department that has more than 1 employee, retrieve the department
number and the number of its employees who are making more than RS 20,000
Display the list of all the employees who work in the same (project,
hours) combination of employee whose ssn=333445555.