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

Sqlserevr Queries Assignment

The document outlines the creation of SQL tables for LOCATION, DEPARTMENT, JOB, and EMPLOYEE, detailing their respective fields and sample data. It also includes a comprehensive list of SQL queries for retrieving and manipulating data from these tables, covering simple queries, conditions, ordering, grouping, sub-queries, joins, and set operators. The queries aim to extract specific employee, department, job, and location information based on various criteria.

Uploaded by

Ibraheem Shaikh
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)
11 views

Sqlserevr Queries Assignment

The document outlines the creation of SQL tables for LOCATION, DEPARTMENT, JOB, and EMPLOYEE, detailing their respective fields and sample data. It also includes a comprehensive list of SQL queries for retrieving and manipulating data from these tables, covering simple queries, conditions, ordering, grouping, sub-queries, joins, and set operators. The queries aim to extract specific employee, department, job, and location information based on various criteria.

Uploaded by

Ibraheem Shaikh
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/ 4

SQL Queries

Create the following Tables:

LOCATION
Location_ID Regional_Group
122 NEW YORK
123 DALLAS
124 CHICAGO
167 BOSTON

DEPARTMENT
Department_ID Name Location_ID
10 ACCOUNTING 122
20 RESEARCH 124
30 SALES 123
40 OPERATIONS 167

JOB
Job_ID [Function]
667 CLERK
668 STAFF
669 ANALYST
670 SALESPERSON
671 MANAGER
672 PRESIDENT

EMPLOYEE
MID
EMPL MANA DEPA
LAST_N FIRST_ DLE_ HIRED SALAR
OYEE JOB_ID GER_I COMM RTME
AME NAME NAM ATE Y
_ID D NT_ID
E
17-
7369 SMITH JOHN Q 667 7902 DEC- 800 NULL 20
84
20-
7499 ALLEN KEVIN J 670 7698 FEB- 1600 300 30
85
04-
7505 DOYLE JEAN K 671 7839 APR- 2850 NULL 30
85
15-
7506 DENNIS LYNN S 671 7839 MAY- 2750 NULL 30
85
10-
7507 BAKER LESLIE D 671 7839 JUN- 2200 NULL 40
85
22-
CYNTH
7521 WARK D 670 7698 FEB- 1250 500 30
IA
85

Queries based on the above tables:


Simple Queries:

1. List all the employee details


2. List all the department details
3. List all job details
4. List all the locations
5. List out first name,last name,salary, commission for all employees
6. List out employee_id,last name,department id for all employees and rename
employee id as “ID of the employee”, last name as “Name of the employee”,
department id as “department ID”
7. List out the employees anuual salary with their names only.

Where Conditions:

8. List the details about “SMITH”


9. List out the employees who are working in department 20
10. List out the employees who are earning salary between 3000 and 4500
11. List out the employees who are working in department 10 or 20
12. Find out the employees who are not working in department 10 or 30
13. List out the employees whose name starts with “S”
14. List out the employees whose name start with “S” and end with “H”
15. List out the employees whose name length is 4 and start with “S”
16. List out the employees who are working in department 10 and draw the salaries more
than 3500
17. list out the employees who are not receiving commission.

Order By Clause:

18. List out the employee id, last name in ascending order based on the employee id.
19. List out the employee id, name in descending order based on salary column
20. list out the employee details according to their last_name in ascending order and
salaries in descending order
21. list out the employee details according to their last_name in ascending order and
then on department_id in descending order.

Group By & Having Clause:

22. How many employees who are working in different departments wise in the
organization
23. List out the department wise maximum salary, minimum salary, average salary of the
employees
24. List out the job wise maximum salary, minimum salary, average salaries of the
employees.
25. List out the no.of employees joined in every month in ascending order.
26. List out the no.of employees for each month and year, in the ascending order based
on the year, month.
27. List out the department id having atleast four employees.
28. How many employees in January month.
29. How many employees who are joined in January or September month.
30. How many employees who are joined in 1985.
31. How many employees joined each month in 1985.
32. How many employees who are joined in March 1985.
33. Which is the department id, having greater than or equal to 3 employees joined in
April 1985.

Sub-Queries

34. Display the employee who got the maximum salary.


35. Display the employees who are working in Sales department
36. Display the employees who are working as “Clerk”.
37. Display the employees who are working in “New York”
38. Find out no.of employees working in “Sales” department.
39. Update the employees salaries, who are working as Clerk on the basis of 10%.
40. Delete the employees who are working in accounting department.
41. Display the second highest salary drawing employee details.
42. Display the Nth highest salary drawing employee details

Sub-Query operators: (ALL,ANY,SOME,EXISTS)

43. List out the employees who earn more than every employee in department 30.
44. List out the employees who earn more than the lowest salary in department 30.
45. Find out whose department has not employees.
46. Find out which department does not have any employees.

Co-Related Sub Queries:

47.Find out the employees who earn greater than the average salary for their
department.

Joins
Simple join

48.List our employees with their department names


49.Display employees with their designations (jobs)
50.Display the employees with their department name and regional groups.
51.How many employees who are working in different departments and display with
department name.
52.How many employees who are working in sales department.
53.Which is the department having greater than or equal to 5 employees and display the
department names in ascending order.
54.How many jobs in the organization with designations.
55.How many employees working in “New York”.

Non – Equi Join:

56.Display employee details with salary grades.


57.List out the no. of employees on grade wise.
58.Display the employ salary grades and no. of employees between 2000 to 5000 range
of salary.

Self Join:

59.Display the employee details with their manager names.


60.Display the employee details who earn more than their managers salaries.
61.Show the no. of employees working under every manager.

Outer Join:

61.Display employee details with all departments.


62.Display all employees in sales or operation departments.

Set Operators:

63.List out the distinct jobs in Sales and Accounting Departments.


64.List out the ALL jobs in Sales and Accounting Departments.
65.List out the common jobs in Research and Accounting Departments in ascending
order.

You might also like