Sie sind auf Seite 1von 5

4121203A LAB 6

Functions
This lab covers the following topics:
o Various types of functions that are available in SQL
o Aggregate functions and GROUP BY clause
o Include or exclude grouped rows by using the HAVING clause
In this practice, you will build more complex reports, including statements that
use the various types of functions e.g. basic calculation, date/time, or string functions.
Also, queries which are related to the aggregation functions will be investigated.
Finally, the joins between two or more tables will be built.
The HR department needs your assistance with creating some queries.
1. Write a query to display the current date. Label the column Date.

_______________________________________________
_______________________________________________
____________________________________________
2. The HR department needs a report to display the employee number, last name,
salary, and salary increased by 15.5% (expressed as a whole number) for each
employee. Label the column New Salary.

_______________________________________________
_______________________________________________
_______________________________________________
_______________________________________________
_______________________________________________

3. Modify your query 2 to add a column that subtracts the old salary from the
new salary. Label the column Increase.

_______________________________________________
_______________________________________________
_______________________________________________
_______________________________________________

4. Write a query that displays the last name (with the first letter uppercase and all
other letters lowercase) and the length of the last name for all employees
whose name starts with the letters J, A, or M. Give each column an appropriate
label. Sort the results by the employees last names.

_______________________________________________
_______________________________________________
_______________________________________________
_______________________________________________

5. The HR department wants to find the length of employment for each


employee. For each employee, display the last name and calculate the number
of months between today and the date on which the employee was hired. Label
the column MONTHS_WORKED. Order your results by the number of
months employed. Round the number of months up to the closest whole
number. Note: Your results will differ.

_______________________________________________
_______________________________________________
_______________________________________________
_______________________________________________

6. Create a report that produces the following for each employee:


<employee last name> earns <salary> monthly but wants <3 times salary>.
Label the column Dream Salaries.

_______________________________________________
_______________________________________________
_______________________________________________
______________________________________________

7. Find the highest, lowest, sum, and average salary of all employees. Label the
columns Maximum, Minimum, Sum, and Average, respectively. Round your
results to the nearest whole number.

_______________________________________________
_______________________________________________
_______________________________________________
_______________________________________________

8. The HR department needs the following reports: Modify the query in 7.sql to
display the minimum, maximum, sum, and average salary for each job type.

_______________________________________________
______________________________________________
_______________________________________________
_______________________________________________

9. Create a report to display the manager number and the salary of the lowestpaid employee for that manager. Exclude anyone whose manager is not
known. Exclude any groups where the minimum salary is $6,000 or less. Sort
the output in descending order of salary.

_______________________________________________
_______________________________________________
_______________________________________________
_______________________________________________

Das könnte Ihnen auch gefallen