[SOLVED] CS SQL database FIT2094 Databases

$25

File Name: CS_SQL_database_FIT2094_Databases.zip
File Size: 310.86 KB

5/5 - (1 vote)

FIT2094 Databases
Session 10 Tutorial Activities
SQL Part II (SQL Intermediate)
FIT Database Teaching Team
Complete session 10 activities in week 5 listed below:
10.1 Using the SQL Developer Query Builder
10.2 SQL Intermediate
10.2.1 Class Discussion
10.2.2 SQL Intermediate Questions
FIT2094-FIT3171 2021 Summer B
FIT2094-FIT3171 Introduction to Databases
Author: FIT Database Teaching Team
License: Copyright Monash University, unless otherwise stated. All Rights Reserved.
COPYRIGHT WARNING
Warning
This material is protected by copyright. For use within Monash University only. NOT FOR RESALE. Do not remove this notice.
Page 1 of 8

Learning Objectives:
be able to use SQL aggregate functions (SUM, AVG, COUNT)
be able to write SQL using GROUP BY Clause
be able to use SQL clause HAVING
be able to use a subquery in SQL
10.1 Using the SQL Developer Query Builder
First, set the preference to open the table using a double click instead of a single click. Open SQL Developer Preferences Database uncheck Open Object on Single Click.
The Query Builder tab is located alongside the Worksheet tab:
Using the Query Builder you can quickly and efficiently create SQL queries or beginning templates. As an example take the query List the student name of all students who have marks in the range
o f 6 0 t o 7 0 .
1. First, we need to identify the tables which will be needed here uni.student and uni.enrolment
Page 2 of 8

2. Drag and drop the tables from the uni account into query builder:
3. Indicate the join condition between the two tables, by dragging the STUDID attribute from STUDENT onto the STUDID attribute of ENROLMENT:
If required the join can be further specified by double-clicking on the join line, for example, to specify this should be an outer join (Select all from the appropriate side)
4. Indicate which attributes you wish to be displayed in the select list by ticking the appropriate boxes:
Right-clicking on an output row offers a number of actions including move up/down to position the item
Page 3 of 8

5. Use the Criteria column to set the WHERE clause:
6. Lastly, specify the sort order:
The query can be run directly from within the Query Builder by selecting the normal Run Statement (the green arrow) as you did in the Worksheet.
Page 4 of 8

Alternatively, if you swap back to the Worksheet, you will see your full SQL query built:
The query builder can help you quickly and efficiently build queries. However, it is very important that you are able to code your own queries in the worksheet and do not depend on the query builder to do the task for you. It is simply a tool you may use in building queries.
Page 5 of 8

10.2 SQL Intermediate
Important
Remember before starting any lab activity which involves working with files, first use SQL Developer to pull from FIT GitLab server to ensure your local files and the FIT GitLab server files are in sync. During this activity, you will be creating a set of SQL scripts, these M UST be sent to the FIT GitLab server.
The following exercises will allow you to be familiar with:
All the SQL statements previously used
Aggregate functions such as min, max, avg The GROUP BY clause
Subqueries
This session we will continue to use the UNIVERSITY database model:
University Data model
Page 6 of 8

10.2.1 Class Discussion
1. Find the maximum mark for FIT9136 in semester 2, 2019.
2. Find the total number of enrolments per semester for each unit in the year 2019. The list should include the unitcode, semester and year. Order the list in increasing order of enrolment numbers.
3. Find the oldest student/s in FIT9132? Display the students full name and the date of birth. Sort the list by student id.
10.2.2 SQL Intermediate Questions
Download session10_sql_intermediate.sql from Session 10 block in Moodle, place this file in your working directory in Tut10 folder. Write your answers for question 1 8 in the provided area. Test the select statement one by one, then when you finish all questions, run the whole script and save the output file as session10_sql_intermediate_output.txt. To save the output, use of the inbuilt Oracle SPOOL command.
1. Find the average mark of FIT2094 in semester 2, 2019. Show the average mark with two decimal places. Name the output column as Average Mark.
2. List the average mark for each offering of FIT9136. In the listing, include the year and semester number. Sort the result according to the year then the semester.
3. Find the number of students enrolled in FIT1045 in the year 2019, under the following conditions:
a. Repeat students are counted each time
b. Repeat students are only counted once
4. Find the total number of prerequisite units for FIT5145.
5. Find the total number of prerequisite units for each unit. In the list, include the unit code for which the count is applicable. Order the list by unit code.
6. Find the total number of students whose marks are being withheld (grade is recorded as WH) for each unit offered in semester 1 2020. In the listing include the unit code for which the count is applicable. Sort the list by descending order of the total number of students whose marks are being withheld.
7. For each prerequisite unit, calculate how many times it has been used as a prerequisite (number of times used). In the listing include the prerequisite unit code, the prerequisite unit name and the number of times used. Sort the output by unit name.
8. Display unit code and unit name of units which had at least 1 student who was granted deferred exam (grade is recorded as DEF) in semester 1 2020. Order the list by unit code.
9. Find the unit/s with the highest number of enrolments for each offering in the year 2019. Sort the list by semester then by unit code.
Page 7 of 8

10. Find all students enrolled in FIT3157 in semester 1, 2020 who have scored more than the average mark of FIT3157 in the same offering? Display the students name and the mark. Sort the list in the order of the mark from the highest to the lowest then in increasing order of student name.
Important
You need to get into the habit of establishing this as a standard FIT2094-FIT3171 workflow pull at the start of your working session, work on the activities you wish to/are able to complete during this session, save the files, add all (stage), commit and then push the changes back to the FIT GitLab server
Page 8 of 8

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[SOLVED] CS SQL database FIT2094 Databases
$25