You are on page 1of 3

Aggregation and Grouping operations

Lab Module

According to the list of tables (Dreamhome database tables) given by your


lecturer, write down the relational algebra, SQL statements and Results:

1. Retrieve the total number of properties.

2. Retrieve average amount of salary earned by the staffs.

3. Retrieve the total number of rooms for the properties in each city.

4. Find the minimum amount of salary by staff’s position.

5. Get the number of staff who holds manager position.

6. Retrieve the minimum, maximum and average rent of flat properties that will be
rent.

7. Find the sum of rental income generated by each branch.


More Exercises

Formulate the following queries in relational algebra and SQL statement.

1. Calculate the total number of staffs who are female. Rename column as
Number Of Female Staff. Display sex column as well.
2. Retrieve the total number of staffs who are assistants. Display position column
as well.
3. List the total salary for each gender.
4. Get the minimum, maximum and average salary for each branch.
5. Get the number of staffs who work at B003 and B007. Please include
BranchNo in your column list.
6. Produce a report of the number of properties handled by each staff.
7. Find out how many properties are owned by ‘C093’.
8. Find out how many properties are viewed by ‘CR56’ and ‘CR76’.
9. The normal rental rate for each property is between RM300 and RM400. How
many properties that do not have this rental rate? Name the column as
TOTALPROPERTIES.
10. List the total number of employees in each branch for those branches with
more than 1 employee. Create an appropriate heading for the columns of the
results table.
11. Find those branches that have two or more female staff.
12. Find those owners that have two or more properties. Sort the output in
descending order of branchno.

Connolly, T. & Begg, C. (2015) Database Systems: A Practical Approach To Design, Implementation, And
Management. 12th Edition. Addison-Wesley.

2
More Exercises

Show the SQL statement, Relational Algebra (RA) and the expected result for
each of the following user queries:

1. Calculate the total number of employees.


2. Calculate the total number of employees who are male.
3. Produce a list of the number of employees who work at B005 and B003.
4. List the total number of all managers who earn more than 25000.
5. List the total number of staffs with a salary not between 20,000 and 30,000.
6. List the total number of employees who manage properties for rent in
Glasgow.
7. List the total number of all properties for rent where a staff has not been
assigned.
8. Produce a list of the total number of female staff.
9. Find out how many owners live in Aberdeen.
10. Find out how many employees earned less than 10000.
11. List the total number of clients who preferred flat with maximum rental less
than 500.
12. Calculate the total number of owners who are from Glasgow.
13. Calculate the total number of properties that have been viewed. Please
eliminate duplicate properties.
14. Retrieve the total number of employees aged between 40 and 60.
15. Retrieve the total number of employees aged between 40 and 60. Exclude
female staff.

Connolly, T. & Begg, C. (2015) Database Systems: A Practical Approach To Design, Implementation, And
Management. 12th Edition. Addison-Wesley.

You might also like