Practice Questions
Practice Questions
1. Display details of jobs where the minimum salary is greater than 50000.
2. Display the first name and join date of the employees who joined between 2001
and 2010.
SELECT FIRST_NAME, HIRE_DATE FROM EMPLOYEESWHERE
TO_CHAR(HIRE_DATE, 'YYYY') BETWEEN 2002 AND 2003 ORDER BY
HIRE_DATE;
SELECT first_name, hire_date from employees where hire_date BETWEEN '1-JAN-
01' AND '1-JAN-03';
3. Display first name and join date of the employees who is either IT Programmer or
Sales Man.
7. Display job Title, the difference between minimum and maximum salaries for jobs
with max salary in the range 10000 to 20000.
SELECT * from employees where First_name LIKE 'K%' OR Last_name LIKE 'K%';
12. Display details of the employees where commission percentage is null and salary
in the range 5000 to 10000 and department is 30.
SELECT * from employees where commission_pct IS null AND salary BETWEEN 5000
AND 10000 AND department_id = 30;
13. Display first name and date of first salary of the employees.
16. Display first name and last name after converting the first letter of each name to
upper case and the rest to lower case.
20. Change salary of employee 115 to 8000 if the existing salary is less than 6000.
UPDATE employees SET Salary = 8000 where employee_id = 115 AND salary <
6000;
21. Insert a new employee into employees with all the required details.
24. Insert a row into departments table with manager ID 120 and location ID in any
location ID for city Tokyo.
26. Display job title, employee ID, number of days between ending date and starting
date for all jobs in department 30 from job history.
Select job_id, employee_Id, (end_date – start_date) As WorkedDays from
job_history where department_id = 30;
27. Display department name and manager first name.
Select departments.department_name, employees.first_name from
departments join employees ON departments.manager_id=
employees.employee_id ;
29. Display first name in upper case and email address in lower case for employees
where the first name and email address are same irrespective of the case.
SELECT UPPER(First_name) First_Name, LOWER(email) Email from employees
where UPPER(First_name) = UPPER(email);
30. Display country name, city, and number of departments where department has
more than 5 employees.
SELECT Country_name, city, COUNT(department_id) FROM Countries JOIN
locations USING (Country_id) JOIN Departments USING (Location_id)
WHERE Department_id IN (SELECT DEPARTMENT_ID From employees GROUP BY
department_id HAVING COUNT(department_id)>5)
GROUP BY country_name, city;
33. Display the departments into which no employee joined in last two years.
SELECT * FROM departments WHERE department_id NOT IN
(SELECT department_id FROM employees WHERE
ROUND((SYSDATE – HIRE_DATE)/365) < 2);
34. Display the details of departments in which the max salary is greater than 10000
for employees who did a job in the past.
SELECT * from departments
WHERE department_id IN (SELECT DEPARTMENT_ID from employees
Where EMPLOYEE_ID IN (SELECT Employee_id from job_history)
GROUP BY Department_id HAVING MAX(Salary) > 10000)
35. Display details of current job for employees who worked as IT Programmers in
the past.
SELECT * from jobs where job_id IN (Select job_id from employees where
Employee_id IN (SELECT Employee_id from job_history where job_id =
'IT_PROG'));
36. Display the details of employees drawing the highest salary in the department.
SELECT first_name, department_id, salary, FROM employees e WHERE salary =
(SELECT MAX(Salary) from employees
WHERE department_id = e.department_id);