Professional Documents
Culture Documents
John|Smith
Ramesh|Narayan
Joyce|English
2. Find the highest paid employee in the ‘Administration’ department.
Command:
select fname, lname, max(salary)
from employee, department
where Dno = Dnumber
and Dname = 'Administration';
Output:
Jennifer|Wallace|43000
3. List the location of department number 1.
Command:
select Dlocation
from dept_locations
where Dnumber = 1;
Output:
Houston
4. Display the count of male employees department number wise.
Command:
select dname, count(fname)
from employee, department
where dno = dnumber and sex = 'M'
group by dname;
Output:
Administration|1
Headquarters|1
Research|3
5. List the name and location of projects which department no.5 manages.
Command:
select pname, plocation
from project
where dnum = 5;
Output:
ProductX|Bellaire
ProductY|Sugarland
ProductZ|Houston
6. List the names of all employees who have a dependent with the same first name as
themselves.
Command:
select fname, lname
from employee
where exists(select * from dependent where dependent_name = fname);
Output:
-Empty-
7. Retrieve the names of all employees in department 5 who work more than 10 hours per week
on the ProductX project.
Command:
select fname, lname
from (employee join works_on on essn = ssn), project
where dno = 5 and hours > 10 and pname = 'ProductX' and pnumber = pno;
Output:
John|Smith
Joyce|English
8.For each department whose average employee salary is more than $30,000, retrieve the
department name and the number of employees working for that department.
Command:
select dname, count(*)
from department, employee
where dnumber = dno
group by dname
having avg(salary) > 30000;
Output:
Administration|3
Headquarters|1
Research|4