Sunteți pe pagina 1din 2

ITE

407 ADVANCED DATABASE MANAGEMENT SYSTEMS Laboratory Exercise 1

Theory: Group Functions in SQL

Group functions are also referred to as aggregate functions. Ordinarily, in SQL, functions work
with single row results. These are the usual functions that will return a single row or present
manipulation based on only one row at a time. Group functions have a function of aggregating
or using several rows in a table to come up with a single result. Examples are totaling, finding
averages, and count. Statistical functions are also available as extensions in most SQL
environments, such as standard deviations, means and min/max.

Notes: This lab must be completed within class time. If any questions are left over, they must
be submitted before the end of the school day.

Objective

The objective of this exercise is to demonstrate group functions with SQL.

Tools/Applications

- Oracle Express covers a lot of group functions for this exercise. MySQL may also be used.
- A script that creates an HR Schema. This can be obtained from your Instructor. If you
use Oracle Express, it is part of the installation.

Lab Activity:

1. Open Oracle Express or MySQL.



2. In this HR schema, you will write a group function that brings out the maximum and
minimum salary of an employee in each department code. [4]

3. Write a group function that will count how many employees in each job ID are getting close
to a minimum salary. [4]

4. Write a group function that will count how many employees in each job_id are getting close
to a maximum salary (Hint: Modify the statement in Question 3). [3]

5. Using the AVERAGE function, write an SQL statement that will show the average salary in
each department. Display the department ID, and the attendant average salary. [4]
6. How many employees in department 80 are getting a salary less or equal to the minimum
salary of department 50? Write a set of SQL statements that you would use to verify your
answer (at least two). [6]


7. Display the employee ID, employee last name, and department ID of all employees whose
salary is less than the average of the whole of the employees table. [4]

Sunday, February 26, 2017

S-ar putea să vă placă și