SQL- Practice Problem1
SQL- Practice Problem1
EMP
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
DEPT SALGRADE
This exercise covers functions not just in the SELECT but in WHERE and ORDER BY clauses. Note the column alias
which have been used.
1. List the employee name and salary increased by 15% and expressed as a whole number of dollars.
2. Display each employee’s name and hiredate from dept. 20.
3. Display each employee name with hiredate, and salary review date. Assume review date is one year after hiredate.
Order the output in ascending review date order.
4. Print a list of employees displaying just the salary amount if more than 1500. If exactly 1500 display ‘On Target’,
if less than 1500 display ‘Below 1500’.
5. Write a query which will return the DAY of the week (i.e. MONDAY,) of hiredate of employees.
6. Employees hired on or before the 15th of any month are paid on the last Friday of that month. Those hired after
the 15th are paid on the last Friday of the following month. Print a list of employees, their hiredate and first pay
date. Sort on hiredate.
7. Write a query to calculate the length of time any employee has been with the company.
1. Display all employee names and their department name, in department name order.
2. Display all employee names, department number and name.
3. Display the name, location and department of employees whose salary is more than 1500 a month.
4. Produce a list showing employees’ salary grades.
5. Show only employees on grade 3.
6. Show all employees in Dallas.
7. List the employee name, job salary, grade and department name for everyone in the company except clerks. Sort
on salary, displaying the highest salary first.
8. Display the department that has no employees.
9. List all employees by name and number along with their manager’s name and number.
10. Modify solution to question 10 to display KING who has no manager.
11. Find the job that was filled in the first half of 1983, and the same job that was filled during the same period in
1984.
12. Find all employees who joined the company before their manager.
Exercise 5 – Subqueries
1. Write a query to display the employee name and hiredate for all employees in the same department as Blake.
Exclude Blake.
2. Create a query to display the employee number and name for all employees who earn more than the average
salary. Sort the results in descending order of salary.
3. Write a query that will display employee number and name for all employees who work in a department with any
employee whose name contains a T.
4. Display the employee name, department number, and job title for all employees whose department location is
Dallas.
5. Display the employee and salary of all employees who report to King.
6. Display the department number, name, and job for all employees in the Sales department.
7. Write a query to display the name, department number, and salary of any employee whose department number
and salary match the department number and salary of any employee who earns a commission.
8. Display the name, department name, and salary of any employee whose salary and commission match the salary
and commission of any employee located in Dallas.
9. Create a query to display the name, hiredate, and salary for all employees who have the same salary and
commission as Scott.
10. Create a query to display the employees that earn a salary that is higher than the salary of all of the clerks. Sort
the results on salary from highest to lowest.