You are on page 1of 5

Practice for home task

Basic
1. Show fname of all employees.
2. Show fname and ssn of all employees.
3. Show all information of all employees.
4. Show fname, ssn and salary of all employees who earns 40,000.
5. Show fname, ssn and salary of all employees who earns more than 40,000 and are working in
dnumber 5.
6. Show fname of emloyees who earns 30,000 or they are female.
7. Show information of employees who have no supervisor.
8. Show fname of employees whose address is saved in our database.
9. Show salary of all employees.
10. Show uniques fname of all employees.
11. Retrieve the birthdate and address of the employee whose name is 'John B. Smith'.
12. Show employees who are working in department # 5 or earn between 20,000 and 40,000
13. Show information of all employees in descending order by their salaries.
14. Show the effect of giving all employees who work in department no 5 a 10% raise. Report should
have four columns: Employee Name, Old Salary, Expected New Salary.
15. Show the employee information who is earning the most.

LIKE
1. Show detail of employee whose first name starts with K and born in 1980.
Practice for home task

2. Show detail of employee whose first name starts with J and last name does not end with d.
3. Show detail of department which has at least 3 alphabets in its name.
4. Show projects which has r in their name and it is on second position.
5. Show projects which does not has H in their name.
6. Show projects which does not has H on second position of their name.
7. Show name of dependent from dependent table, where dependent name starts with D and has
at least 3 characters.
8. Show detail of employee whose first name starts with A and ends with A.
9. Show name of emploees who have 5 digit salary.
10. Shaw name of employees who live in “Texas”.

Join
1. Show department name with its manager’s name
2. Show project name with its department name.
3. Show employee name with its dependent name.
4. Show employee name with the name of project he is working on.
5. Show employee name with its supervisor name.
6. Display name of manager and the date he starting managing the department.
7. Show department name with its department location.
8. Name the employee who works on a project that is located in ‘Stafford’.
9. Name the employees who work on the project that is controlled by dept 5.
10. Name the employees who manage ‘Research’ department and are earning more than 10000.
11. Name all employees who have a dependents with the same first name as theirs.
12. Name employees of dept 5 who works more than 10 hours in any project.
13. Employee name who are directly supervised by ‘franklin Wong’.
14. Retrieve name and address of all employees who work for research department.
15. For every project located in ‘Stafford’, list the project number, the controlling dept number, dept
manager’s last name, address and birthdate.
16. List names of managers who have at least on dependent.
17. Show employee First name with its department name.
18. Name the employees who work on a project that is located in “Stafford”.
19. Retrieve name and address of all employees who works for research department.
20. Show managers with their dependent names whether they have any dependent or not.
21. Show project names along with the employee names working on it whether there are some
employees working on it or not.
22. Show department names along with their locations for those departments whose location has ‘ton’
in its name.
23. Name employees who have a son born in May with the same name as the employee’s first name.
24. Name employees who work on project located at Stafford and project is controlled by a dept which
is located at ‘Houston’

Aggregate Function
1. Show average salary of all employees.
2. Show total number of departments.
Practice for home task

3. Show sum of hours spent on all projects.


4. Show average salary of each department if average salary is greater than 40,000.
5. Show minimum salary of each department if minimum salary is less than 20,000.
6. Show total number of employees of each department with department name.
7. Show number of dependent of each employee.
8. Show sum of projects of all departments in ascending order by department name.
9. Show count of total locations of each department which are located in Lahore.
10. For each project show project name and total number of employees working on it.
11. Show total number of employees of each department with more than 10 employees.
12. For each department which has average salary more than 50000 show departnames along
with the total number of employees working in it.
13. Show employees who have two or more dependents.
14. Show employee name who has minimum salary.
15. Show employee name who has maximum salary.
16. Show department name with employee name who has maximum salary.
17. Show all project names along with the total number of employees working in it and total
number of hours they spent on project, only for the projects which are controlled by
research department.

Set operations
1. Show department names in which some workers works with salary> 30,000 or it is
located in Stafford.
2. Show employee ssn’s who are managers but don’t have any dependents.
3. Show manager name who have no dependents.
4. Make a list of all project numbers for projects that involve an employee whose last
name is smith either as a worker or as a manager of dept who controls the project.
5. List names of employees who do not work on any project.
6. Fine the names of all employees who work on atleast one project located in Houston
but whose department has not located in Houston.

Nested Query

1. Show employee names who are managers and they have at least one dependent.
2. Show employee name who are managers but they do not have dependents.
3. Show employee name whose supersssn is same as superssn of either “javed” or
“ahmad”.
4. Show project name on which Aliya is not working.
5. Show all dependent name of employees working in IT department.
6. Show employee names who work in research department.
7. Show project names in which an employee ‘John Smith’ works.
Practice for home task

8. Show all project names which are controlled by a department in which ‘John Smith’
works.
9. Show employee names who has a supervisor with the same salary as themselves.
10. Show employee names who do not work on any project.
11. Show department names which are not controlling any project and has a location in
Houston.

Approach : Corelated Queries.

1. Show department names which have at least one employee.

select Dname
From department
where exists(select * from employee where Dno=Dnumber);

2. Show department names which have no managers.


3. Show employee names who are not supervisors.

select e.Fname

From employee e
Where NOT EXISTS( select e1.Super_ssn from employee e1 where e.Ssn=e1.Super_ssn);

4. Show department names with total number of employees in them.


Select Dname, (Select count(Ssn)

From Employee

Where Dno=Dnumber)

From Department;
5. Show department names with total number of projects they are controlling.
Select Dname, (Select count(Pnumber)

From Project

Where Dnumber=Dnum)

From Department;

6. Show employee names who supervise other employees.


7. Show department names which have the highest number of projects running (do not use LIMIT)
Practice for home task

8. Find the employee names whose hours are same as the highest number of hours spent by any
employee on the same project.
9. Finds all employees whose salary is higher than the average salary of the employees in their
departments
10. Show employee name, their salary and average salary of the department he works in.

You might also like