0% found this document useful (0 votes)
2 views3 pages

SQL Server Assignment

The document outlines various SQL queries for retrieving employee data from a database, including selecting specific columns, filtering results based on conditions, and performing joins and aggregations. It covers tasks such as displaying employee details, salaries, and department information, as well as calculating averages and counts. Additionally, it includes examples of subqueries and sorting data to meet specific requirements.

Uploaded by

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

SQL Server Assignment

The document outlines various SQL queries for retrieving employee data from a database, including selecting specific columns, filtering results based on conditions, and performing joins and aggregations. It covers tasks such as displaying employee details, salaries, and department information, as well as calculating averages and counts. Additionally, it includes examples of subqueries and sorting data to meet specific requirements.

Uploaded by

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

Page 1 of 3

Basic SELECT Statements

1. Create a query to display the last name, job code, hire date, and employee number for each employee, with
employee number appearing first. Provide an alias STARTDATE for the HIRE_DATE column.
2. Create a query to display unique job codes from the EMPLOYEES table.
3. Display the last name concatenated with the job ID, separated by a comma and space, and name the column
Employee and Title
Restricting and Sorting Data

4. Create a query to display the last name and salary of employees earning more than $12,000.
5. Create a query to display the employee last name and department number for employee number 176.
6. Display the last name and salary for all employees whose salary is not in the range of $5,000 and $12,000.
7. 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.
LAST_NAME JOB_ID HIRE_DATE
Matos ST_CLERK 15-mar-98
Taylor SA_REP 24-mar-98

8. Display the last name and department number of all employees in departments 20 and 50 in alphabetical
order by name

9. List the last name and salary of employees who earn between $5,000 and $12,000,
and are in department 20 or 50.
EMPLOYEE MONTHLY SALARY
Mourgos 5800
Fay 6000

10. Display the last name and hire date of every employee who was hired in 1994.
11. Display the last name and job title of all employees who do not have a manager.
LAST_NAME JOB_ID
King AD_PRES

12. Display the last name, salary, and commission for all employees who earn commissions. Sort data in
descending order of salary and commissions.
13. Display the last name of all employees where the third letter of the name is an a.
14. Display the last name of all employees who have an a and an e in their last name
15. 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 $2,500, $3,500, or $7,000.
16. Display the last name, salary, and commission for all employees whose commission amount is 20%.
Expressions and Simple Calculation in Queries

17. For each employee, display the employee number, lat_name, salary, and salary increase by 15% and
expressed as a whole number. Label the column New Salary.
18. Modify above query to add a column that subtract the old salary from the new salary. Label the column
Increase.
19. write a query that produces the following for each employee:
 <employee last name> earns <salary> monthly but wants <3 times salary>. Label the column
Dream Salary.
Page 2 of 3
 For Example: King earns $24,000 monthly but wants $72,000.
Displaying Data from Multiple Tables (Joins)
20. Write a query to display the last name, department number, and department name for all employees.
21. Write a query to display the employee last name, department name, location ID, and city of all employees
who earn a commission
22. Display the employee last name and department name for all employees who have an a in their last names.
23. Write a query to display the last name, job, department number, and department name for all employees who
work in Toronto.
24. Create a query that displays employee last name, department number, and ll the employee who work in the
same department as a given employee. Give each column an appropriate label
DEPARTMENT EMPLOYEE COLLEAGUE
20 Fay Hartstein
20 Hartstein Fay
50 Davies Matos
50 Davies Mourgos
50 Davies Rajs
50 Davies Vargas
50 Matos Davies
50 Matos Mourgos
.
.
.
42 rows selected.
25. Display the employee last name and employee number along with their manager’s last name and manager
number. Label the column Employee, Emp#, Manager, and Mgr#.
26. Modify above query to display all employees including King (who has no manager)
27. Create a query that displays the name, job, department name, salary, and grade for all employees (Join
Employees, Departments & Job_Grades Tables)
28. Create a query to display the name and hire date of any employee hired after employee Davies.
29. Display the names and hire dates for all employees who were hired before their managers, along with their
manager’s names and hire dates.
Aggregating Data Using Group Functions & Group by Clause
30. Display the highest, lowest, sum and average salary of all employees.

31. Display the minimum, maximum, sum, and average salary for each job type.
JOB_ID MAXIMUM MINIMUM SUM AVERAGE
AC_ACCOUNT 8300 8300 8300 8300
AD_VP 17000 17000 34000 17000
IT_PROG 9000 4200 19200 6400
ST_CLERK 3500 2500 11700 2925
.
.
.
12 rows selected

32. Write a query to display the number of people with the same job.
JOB_ID COUNT(*)
AC_ACCOUNT 1
AD_PRES 1
AD_VP 2
IT_PROG 3
ST_CLERK 4
.
Page 3 of 3
.
12 rows selected

33. Determine the number of manager without listing them. Label the column Number of Manager. Hint: User
the Manager_ID column to determine the number of managers.
34. Write a query that displays the difference between the highest and lowest salaries. Label The column
Difference.
35. Display the manager number and the salary of the lowest paid employee for that manager. Exclude anyone
whose manager is not known. Exclude any group where the minimum salary is $6,000 or less. Sort the output
in descending order of salary.
Manager_ID MIN(SALARY)
102 9000
205 8300
149 7000

36. 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 columns Name, Location, Number of People, and Salary,
respectively.
Subqueries
37. Write a query to display the last name and hire date of any employee in the same department as Zlotkey.
Exclude Zlotkey.
38. Create a query to display the employee numbers and last names of all employees who earn more than the
average salary. Sort the results in ascending order of salary.
39. Write a query that displays the employee numbers and last names of all employees who work in a department
with any employee whose last name contains a u.
40. Display the last name, department number, and job ID of all employees whose department location ID is
1700.

41. Display the last name and salary of every employee who reports to King.
LAST_NAME SALARY
Kochhar 17000
De Haan 17000
Mourgos 5800
Zlotkey 10500
Hartstein 13000
42. Display the department number, last name, and job ID for every employee in the Executive Department.
DEPARTMENT_ID LAST_NAME JOB_ID
90 King AD_PRES
90 Kochhar AD_VP
90 De Haan AD_VP

You might also like