lab_06_db

7
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. _______________________________________ _______________________________________ ________________ _______________________________________ _______________________________________ _______________________________________ ________________________

Upload: ashwin-kumar

Post on 12-Nov-2014

30 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Lab_06_DB

4121203A LAB 6Functions

This lab covers the following topics:

o Various types of functions that are available in SQLo Aggregate functions and GROUP BY clauseo 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.

Page 2: Lab_06_DB

____________________________________________________________________________________________________________________________________________________________________________________________

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.

____________________________________________________________________________________________________________________________________________________________________________________________

Page 3: Lab_06_DB

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.

___________________________________________________________________________________________________________________________________________________________________________________________

Page 4: Lab_06_DB

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.

___________________________________________________________________________________________________________________________________________________________________________________________

Page 5: Lab_06_DB

9. Create a report to display the manager number and the salary of the lowest-paid 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.

____________________________________________________________________________________________________________________________________________________________________________________________