You are on page 1of 3

CPCS 241 - Lab Activity

Name: Anfal Alatawi


ID: 1617134
Section: GAR
I used https://www.tutorialspoint.com/execute_sql_online.php to do this because I did not have
Oracle installed, that’s why output format is different.
1. Find the names of all employees who are directly supervised by ‘Franklin Wong’.
Command:
select E.fname, E.lname
from Employee as E, employee as S
where S.fname = 'Franklin'
and S.lname = 'Wong'
and E.super_ssn = S.ssn;
Output:

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

You might also like