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

SQL Queries for Practice

The document contains a comprehensive list of SQL queries for practice, covering various operations such as displaying records from different tables, filtering data based on conditions, and formatting output. It includes tasks like joining tables, renaming columns, and calculating aggregates, aimed at enhancing SQL skills. The queries are structured to address a wide range of scenarios, from basic retrieval to complex data manipulation.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views

SQL Queries for Practice

The document contains a comprehensive list of SQL queries for practice, covering various operations such as displaying records from different tables, filtering data based on conditions, and formatting output. It includes tasks like joining tables, renaming columns, and calculating aggregates, aimed at enhancing SQL skills. The queries are structured to address a wide range of scenarios, from basic retrieval to complex data manipulation.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

The Launcher Academy

Office NO- 17/18, 2nd Floor, City Center Opposite – Gossner College, Club Road, Ranchi, Contact
No. 8877155769, 7903154392. 1

SQL QUERIES FOR PRACTICE 1

1. Display all records from "Locations" table


2. Display all records from "Departments" table.
3. Display first name, last name, salary from employees table
4. Display first name, last name, manager id, department id of each employees.
5. Display all records in "Employees table whose salary in range 10000 and 50000
6. Display all records in "Employees table whose department Id is 20
7. Display all records in "Employees table whose department Id is 30 and salary>2300
8. Display all records in "Employees table whose department Id is 40 or salary<4500
9. Display all records in "Employees table whose department Id is 20 and salary not equal to 2300
10. Display all records from locations table where the city is either Geneva or Bern.
11. Create a query to display unique job code from employees table.
12. Name the column heading emp#, employee, job and hire_date instead of emp_id, last_name, job_id,
hire_date.
13. Display column heading employee instead of employee id without using double quotes (").
14. Name the column heading one that is employee instead of display two column heading i.e. last name
and job id.
15. Combine two column heading i.e. last name and job id with a literal character string “is a” with a new
column heading employee details.

16. How to display the output which is given below


MONTHLY
King: 1 month salary=24000
where king is last name, 24000 is salary
MONTHLY is the column heading name and (:1 month salary=) is a literal character string.
17. Create a query to display the last name and salary of employees earning more than 12000.
18. Create a query to display the employee last name and department id for emp_id 176.

19. Display the last name and salary for all employees whose salary is not in the range of 5000, 12000.

20. Display the employee id last name, job id and hire date of employees hired between FEB 20, 1998 and
MAY 1, 1998. Order the query in ascending order by hire date.
The Launcher Academy
Office NO- 17/18, 2nd Floor, City Center Opposite – Gossner College, Club Road, Ranchi, Contact
No. 8877155769, 7903154392. 2
21. Display the last name and dept_no off all employees in departments 20 and 50 in alphabetical order by
name.
22. List the last name and salary of employees whose monthly salary b/w 5000 and 12000 and are in
department 20 or 50. Label the column employee and monthly salary instead of last name and salary.

23. Display the last name and hire date of every employee who was hired in 1994.
24. Display the last name and job title of all employees who do not have a manager.
25. Display the last name and dept_no off all employees in departments 20 and 50 in alphabetical order by
last name.

26. Display the last name, salary and commission of all employees who earn commission's. Sort the data
in descending order of salary and commission.

27. Display the last name of all employees where the 3'rd letter of the name is an "a".

28. Display the last name of all employees who have an "a" and an "e" in their last name.

29. Display the last name, job and salary for all employees whose job is sales representative or stock clerk
and whose salary is not equal to 2400, 3500, and 7000.

30. Display the difference between Round() and Trunc() with example.

31. Display the String in difference case formats.

32. Write a query to display the Last name, job, department number and department name for all
employees who work in ‘toronto’.

33. Display the employee Last name, employee number along with their managers last name and
manager’s number. Label the columns as Employee, EmployeeID, Manager, ManagerID respectively.

34. Display the employee Last name, employee number along with their managers last name and
manager’s number. Label the columns as Employee, EmployeeID, Manager, ManagerID respectively.
Modify this query to display all employees including king, who has no manager.

35. Create a query that displays employee last name, department number and all the employees who work
in the same department as a friend employee. Give each column an appropriate label.
The Launcher Academy
Office NO- 17/18, 2nd Floor, City Center Opposite – Gossner College, Club Road, Ranchi, Contact
No. 8877155769, 7903154392. 3
36. Display the names and hire dates for all employees who were hired before their manager along with
their manager’s names and hire dates. Label the columns Employee, Emp_hired, Manager, Mgr_hired
respectively.

37. Eliminate the extra spaces and join ("the oracle") and (" package").
38. Extract 'cut' from 'calcutta' and join it with 'tack'.
39. Display 120000 with Left padding and right padding when maximum character is 10. Padding
character is #.
40. Create a query to display all the data from employee table. Separate each column by a comma. Name
the column The Output.
41. Display the last name, job id and commission for all employees who are not entitled to get a
commission.
42. Display the last name and job id of all employees whose job id is not IT_PROG, ST_CLERK and
SA_REP.
43. Display the information of all employees whose last name does not contains the character ‘A’.
44. Display the last name, salary and job id of all employees who are entitled to get the commission.
45. Display the record if the employee is a president and earn more than 15,000 or if the employee is a
sales representative.
46. Display the records if an employee is a president or a sales representative and if the employees earns
more than 15,000.
47. Display the records of the employees either working in a department 80 or 90 and getting more than
2000 salary.
48. Display the recodes of employees working in the department 60, 70, 80, 90 and getting salary more
than 5000.
49. Display the record of the employees whose either last name containing the character ‘n’ and working
in the department 80 or last name containing a character ‘s’ and working in the department 60.
50. Display the list of employees who are joined as a clerk (ST_CLERK) between the year 97 and 99.
52. Display the job id, last name, salary, hire date of all employees joined the company as a post of either
clerk or sales representative in the year 98.
53. Display the job id, last name, hire date and department of all employees who are joined in the
department 50 as a post of clerk in the year 98.
54. Display all the record of employees those are joined as post of clerk and sales representative earning
more than 5000 and joined in the year 98.
55. Display last name, department id and hire date of all employees in the descending order of department
id and ascending order of hire date.
The Launcher Academy
Office NO- 17/18, 2nd Floor, City Center Opposite – Gossner College, Club Road, Ranchi, Contact
No. 8877155769, 7903154392. 4
56. Display the employee last name, job id, and start date of employees hired between February 20, 1998
and may 1, 1998. order the query in ascending order by start date.
57. Display the last name, and department number of all employees in department 20 and 50in
alphabetical order by name.

58. Display the last name of all employees who have an ‘a’ and an ‘e’ in their last name.
59. Display the last name, job id and salary of all employees whose job is sales representative (SA_REP)
or stock clerk (ST_CLERK) and whose salary is not equal to 2500, 3500 or 7000.
60. Display the information of employees in the ascending order of annual salary.
61. Display the employee id, last name, salary and salary increased by 15% and expressed as a whole
number and label the column New Salary.
62. Write a query that display the employee’s last name with all the letter capitalized and the length of the
names, for all employees whose last name starts with J, A, or M. sort the result in the descending order of
last name.
63. For each employee display the employees last name and calculate the number of months between
today and the date of the employees was hired. Label the column MONTHS_WORKED. Order your
query result by number of month employed. Round the number of months up to closest whole number.
64. Write a query to produces the following output for each employees.
Dream Salary
King earns $24,000.00 monthly but wants $72000.
Kochhar earn $20,000.00 monthly but wants $60000.
---------------------------------------------------------------
---------------------------------------------------------------
65. Create a query to produce the last name and salary of all employees. Format the salary to be 15.
Last name Salary
King **********24000
Kochhar **********20000
66. Compare hire dates for all employees who started in 1997. Display the employee id, hire date and the
month started using the round( ) and trunk( ) function.
67. Display the employee id, six month review date, first Friday after hire date and last day of the month
when hired for all employees employed for fewer than 36 months.
68. Display the last name, hire date of all employees in the given format.
Last name Hire Date
King Seventeenth of June, 1987
Kochhar Twenty-First of September, 1989.
--------- ----------------------------------------
The Launcher Academy
Office NO- 17/18, 2nd Floor, City Center Opposite – Gossner College, Club Road, Ranchi, Contact
No. 8877155769, 7903154392. 5
69. Display the last name, hire date and day of the week on which the employee started. Label the column
DAY.
70. Create a query that displays the employees last name and commission amount. If the employees does
not get the commission, put “NO COMMISSION”. Label the column COMM.

71. Using the decode function, write a query that displays the grade of all employees based on the value of
the column JOB ID, as per the following table.
JOB GRADE
AD_PRES A
ST_MAN B
IT_PROG C
SA_REP D
ST_CLERK E
None of above O
72. Rewrite the above statement in the preceding question using the CASE syntax.
73. Write the query to display the last name, department number and the department name for all
employees.
74. Show all data for clerk hired after the year 1997.
75. Show the employees who have no commission, but have a 10% raise in their salary (Round off the
salaries)
76. Show the last name of all employees together with the number of years and the number of completed
months that they have been employed.
77. Show those employees that have a name starting with J, K and L character using substr ( ) function.
78. Show all the employees and indicate with “YES” and “NO” whether they receive a commission.
79. Show the department name, city, last name, job title and salary of employees who work in the location
1800.
80. How many employees have a name that ends with an ‘n’. Write the query using substr ( ) function.
81. Show names and locations of all departments and number of employees working in each department.
Make sure that departments without employees are included as well.
82. Show distinct jobs are found in the department 10 and 20.
83. Which jobs are found in the administrative and executive departments and how many employees do
these jobs? Show the jobs with the highest frequency first.
84. Show all employees who were hired in the first half of the month ( before the 16 th of the month)
85. Show the names, salaries and the number of dollars(in thousand) that each employees earns.
86. Show all employees who have managers with a salary higher than $15000. Show the following data:
Manager name, manager salary and salary of the manager.
The Launcher Academy
Office NO- 17/18, 2nd Floor, City Center Opposite – Gossner College, Club Road, Ranchi, Contact
No. 8877155769, 7903154392. 6
87. Create a unique listing of all jobs that are in department 80. Include the location of the department in
the output.
88. Write a query to display employee last name, department name, location id and city of all employees
who earn a commission.

89. Display the employee last name and department name for all employees who have an ‘a’ in their last
name.
90. Write a query to display the last name, job id, department id and department name for all employees
who work in the “Toronoto” city.
91. Display the employees last name and employee id along with their manager’s last name and the
manager id.
92. Modify the above query to display all employees including King, who has no manager. Order the
result by the employee id.
93. Create a query that displays the last name, job id, department name, salary and grades for all
employees.
94. Determine the validity of the following statements. Answer in TRUE/ FALSE
a) Group function work across many rows to produce one result per group.
b) Group function include NULL in calculation.
c) The where clause restricts rows prior to the inclusion in a group calculation.
95. Display the highest, lowest, sum and average salary of all employees. Label the columns Maximum,
Minimum, Sum and average respectively. Round your query result to the nearest whole numbers.
96. Modify the above query to display the minimum, maximum, sum, average salary for each job title.
97. Write a query to display the number of people with the same jobs.
98. Determine the number of managers without listing them. Label the column Number of Manager.
99. Write a query that displays the difference the highest and lowest salaries. Label the column Difference.
100. Write a query to display each department’s name, location, number of employees and the average
salary for all employees in that department. Label the column name, location, number of people and salary
respectively. Round the average salary to two decimal places.
101. Create a query that will display the total number of employees hired in 1995, 1996, 1997 and 1998.
Create appropriate column headings.
102. List out the no. of employees joined in every month in the ascending order.
103. List out the no. of employees for each month and year, in ascending order based on year and month.
104. List out the department id having at least four employees.
105. How many employees in January month.
106. How many employees who are joined in January or September month.
107. How many employees joined in 1985.
108. How many employees joined each month in 1985.
The Launcher Academy
Office NO- 17/18, 2nd Floor, City Center Opposite – Gossner College, Club Road, Ranchi, Contact
No. 8877155769, 7903154392. 7
109. How many employees joined in March 1985.
110. Which is the department id, having greater than or equal to 3 employees joined in the April 1985.
111. Display the employee who got the maximum salary.

112. Display the employees who are working in the sales department using sub query.
113. Display the information of employees getting second highest salary in the company.
114. List out the employees who earn more than every employee in the department 80.
115. List out the employees who earn more than the lowest salary in department 80.
116. Find out whose employees does not have department.
117. Find out the department does not have any employees.
118. Find out the employees who earn greater than the average salary for their department.
119. Display the employee details with their manager details.
120. Display the employee details who earn more than their manager’s salaries.
121. Show the number of employees working under every manager.
122. Display employee details with all departments.

You might also like