0% found this document useful (0 votes)
41 views15 pages

Kanja

Uploaded by

kanjatish
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views15 pages

Kanja

Uploaded by

kanjatish
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 15

SORTING and FILTERING on HR Database

SCREENSHOTS ANSWERS.
1. From the employees table, write a SQL query to find those employees
whose salary is less than 6000. Return full name (first and last name),
and salary

2. From the employees table, write a SQL query to find those employees
whose salary is higher than 8000. Return first name, last name and
department number and salary.
3. From the employees table, write a SQL query to find those
employees
whose last name is "McEwen". Return first name, last name and
department
ID

4. From the employees table, write a SQL query to find those


employees
who have no department number. Return employee_id,
first_name,
last_name, email,phone_number,hire_date,
job_id,
salary,commission_pct,manager_id and department_id.

5. From the employees table, write a SQL query to find those


employees
whose first name does not contain the letter ‘M’. Sort the result-set
in
ascending order by department ID. Return full name (first and last
name
together), hire_date, salary and department_id.

6. From the employees table, write a SQL query to find those employees
who falls in the employees criteria : 1. whose salary is in the range
of
8000, 12000 (Begin and end values are included.) and get
some
commission. 2. : those employees who joined before ‘2003-06-05’
and
not included in the department number 40, 120 and 70. Return all fields.
Sample Solution:

7. From the employees table, write a SQL query to find those


employees
whose salary is in the range 9000,17000 (Begin and end values
are
included). Return full name, contact details and
salary.
8. From the employees table, write a SQL query to find those
employees
whose first name ends with the letter ‘m’. Return the first and last name,
and
salary

Sample Solution:

9. From the employees table, write a SQL query to find those employees
whose salary is not in the range 7000 and 15000 (Begin and end
values
are included). Sort the result-set in ascending order by the full name
(first and last). Return full name and salary.

10. From the employees table, write a SQL query to find those
employees
who were hired during November 5th, 2007 and July 5th, 2009.
Return
full name (first and last), job id and hire date.

Sample Solution:
11. From the employees table, write a SQL query to find those
employees who works either in department 70 or 90. Return full name
(first and last name), department id.

12. From the employees table, write a SQL query to find those
employees
who work under a manager. Return full name (first and last
name),
salary, and manager
ID
13. From the employees table, write a SQL query to find those
employees
who were hired before June 21st, 2002. Return all fields.

14. From the employees table, write a SQL query to find those
employees
whose managers hold the ID 120 or 103 or 145. Return first name,
last
name, email, salary and manager
ID
15. From the employees table, write a SQL query to find those
employees
whose first name contains the letters D, S, or N. Sort the result-set
in
descending order by salary. Return all fields.

16. From the employees table, write a SQL query to find those
employees
who earn above 11000 or the seventh character in their phone
number
is 3. Sort the result-set in descending order by first name. Return full
name (first name and last name), hire date, commission percentage,
email, and telephone separated by '-', and
salary

17. From the employees table, write a SQL query to find those employees
whose first name contains a character ‘s’ in 3rd position. Return
first
name, last name and department id.

18. From the employees table, write a SQL query to find those
employees
who are working in the departments, which are not included in
the
department number 50 or 30 or 80. Return employee_id, first_name,
job_id, department_id.

19. From the employees table, write a SQL query to find


those
employees whose department numbers are included in 30 or 40 or 90.
Return employee id, first name, job id, department id.

20. From the employees table, write a SQL query to count the
number of
employees, sum of all salary, and difference between the highest
salary
and lowest salary by each job id. Return job_id, count,
sum,
salary_differenc
e

21. From the employees table, write a SQL query to count the number of
employees worked under each manager. Return manager ID and
number of employees.

22. From the employees table, write a SQL query to find all those
employees who are either Sales Representative or Salesman. Return
first name, last name and hire date.
23. From the employees table, write a SQL query to calculate average
salary of those employees for each department who get a
commission
percentage. Return department id, average salary.

24. From the employees table, write a SQL query to find


those
departments where a manager can manage four or more
employees.
Return
department_id.
25. From the employees table, write a SQL query to find those
employees
who have no commission percentage and salary within the range 7000,
12000 (Begin and end values are included.) and works in
the
department number 50. Return all the fields of employees.

26. From the employees table, write a SQL query to find those
employees
whose first name or last name starts with the letter ‘D’. Return first
name, last
name.

27. From the employees table, write a SQL query to find those
employees
who joined after 7th September 1987. Return all the fields

You might also like