0% found this document useful (0 votes)
346 views

Practice Questions

This document contains 38 practice questions on SQL queries related to retrieving employee, job, and department data from various tables. The questions cover a range of SQL concepts like filtering on conditions, aggregations, joins, subqueries, functions and more.

Uploaded by

Samiksha Basnet
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
346 views

Practice Questions

This document contains 38 practice questions on SQL queries related to retrieving employee, job, and department data from various tables. The questions cover a range of SQL concepts like filtering on conditions, aggregations, joins, subqueries, functions and more.

Uploaded by

Samiksha Basnet
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Practice Questions

1. Display details of jobs where the minimum salary is greater than 50000.

SELECT * from jobs where min_salary >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.

SELECT First_name, hire_date from employees where job_id IN ('IT_PROG',


'SA_MAN');
4. Display employees who joined after 1st January 2012.

SELECT * from employees where hire_date>('01-JAN-012');

5. Display details of employee with ID 152 or 180.

SELECT * FROM employees where employee_ID IN(152, 180);


6. Display first name, salary, commission pct, and hire date for employees with salary
less than 10000.

SELECT first_name, salary, commission_pct, hire_date from employees where


salary < 10000;

7. Display job Title, the difference between minimum and maximum salaries for jobs
with max salary in the range 10000 to 20000.

SELECT job_title, max_salary, (max_salary – min_salary) from jobs where


max_salary BETWEEN 10000 AND 20000;

8. Display first name, salary, and round the salary to thousands.

SELECT first_name, salary, ROUND(Salary, -3) From Employees;

9. Display details of jobs in the descending order of the title.

Select * from jobs ORDER BY job_title DESC;


10. Display employees where the first name or last name starts with K.

SELECT * from employees where First_name LIKE 'K%' OR Last_name LIKE 'K%';

11. Display employees who joined in the month of June.

SELECT * from employees where TO_CHAR(HIRE_DATE, 'MON') = 'JUN';

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.

SELECT first_name, hire_date, LAST_DAY(hire_date) As "Salary Day"


from Employees;
14. Display first name and experience of the employees.

Select Employees.first_name, Job_history.start_date, Job_history .end_date,


Round((Job_history.end_date- Job_history.start_date)/365) As
"Experience" from Employees JOIN job_history ON
Employees.Employee_id = Job_history.Employee_id;
15. Display first name of employees who joined in 2001.

SELECT first_name from employees where TO_CHAR(HIRE_DATE, 'YYYY') = '2001';

16. Display first name and last name after converting the first letter of each name to
upper case and the rest to lower case.

SELECT INITCAP(First_name) AS First_Name, INITCAP(Last_name) As Last_name


from employees;
17. Display the first word in job title.
SELECT JOB_TITLE, SUBSTR(JOB_TITLE,1, INSTR(JOB_TITLE, ' ')) FROM JOBS;
18. Display the length of first name for employees where last name contain
character ‘b’ after 3rd position.
SELECT first_name, last_name, LENGTH(first_name) from employees where
INSTR(last_name, 'b')>3 ;Display department ID, year, and Number of employees
joined.
19. Display departments where any manager is managing more than 5 employees.

SELECT distinct department_id from employees GROUP BY manager_id,


department_id having count(employee_id)>5;

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.

INSERT INTO EMPLOYEES (EMPLOYEE_ID, FIRST_NAME, LAST_NAME, EMAIL,


PHONE_NUMBER, HIRE_DATE,JOB_ID, SALARY, DEPARTMENT_ID)
VALUES (207, 'RIAN', 'LEE','RIAN','110 903 2339', SYSDATE, 'IT_PROG', 10000, 60);

22. Delete department 20.

DELETE FROM departments where department_id = 20;

23. Change job ID of employee 110 to IT_PROG if the employee belongs to


department 10 and the existing job ID does not start with IT.

UPDATE employees SET job_id = 'IT_PROG' where employee_id = 110 AND


Department_id = 10 AND NOT Job_id LIKE 'IT%';

24. Insert a row into departments table with manager ID 120 and location ID in any
location ID for city Tokyo.

INSERT INTO DEPARTMENTS (Department_id, Department_name, manager_id,


location_id)
VALUES (280, 'Design', 120,1200);
25. Display department name and number of employees in the department.

SELECT department_name, COUNT(employee_id) AS employee_number from


emp_details_view GROUP BY department_name
;

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 ;

28. Display department name, manager name, and city.

SELECT departments.department_name, employees.first_name, locations.city


from departments JOIN employees
ON employees.employee_id= departments.manager_id JOIN Locations USING
(Location_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;

31. Display details of manager who manages more than 5 employees.


SELECT first_name from employees WHERE Employee_id IN
(SELECT manager_id from employees group by manager_id HAVING
COUNT(manager_id)>5)
;
32. Display employee name, job title, start date, and end date of past jobs of all
employees with commission percentage null.

SELECT first_name, job_title, start_date, end_date from job_history jh JOIN jobs


j USING (job_id) JOIN employees e on (jh.employee_id = e.employee_id)
WHERE commission_pct IS NULL;

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);

37. Display the city of employee whose employee ID is 105.


SELECT city from locations where location_id = (SELECT location_id from
departments WHERE department_id = (Select department_id from employees
where employee_id = 105 ));
;
38. Display third highest salary of all employees

You might also like