0% found this document useful (0 votes)
116 views15 pages

SQL Practical Test 2 Semester 2, 2014 ISCG5423 Introduction To Databases

Download as docx, pdf, or txt
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 15

ISCG 5423 Introduction to Databases (Version A)

TEST Exam Login: ................................... Last Name:


......................................
First
Name: .....................................
Class Number: .................................. Student
ID: ......................................
SQL Practical Test 2
Semester 2, 2014

ISCG5423 Introduction to
Databases

Date: Monday 6
Department of Computing October 2014
Time: In class
Time Allowed: 120 minutes
Weighting: 25%
Marks: 100

Instructions:
1. This is CLOSED BOOK test but there are materials available in the exam S:
drive that you may use for reference.
2. Calculators, dictionaries and any form of electronic devices are NOT
PERMITTED.
3. Write your Name, Student ID, and Class Number in the space provided at
the top of this paper version and in the SQLAnswerA2.sql file.
4. All answers are to be written in the SQLAnswerA2.sql file (use the template
provided) which can be found in your exam directory. Save this file regularly
during the test.
5. Check that the data set (see Appendix) matches the tables that are in the
exam directory.
6. On completion of this test, check that you have entered your Name, Student
ID and Class Number in both this paper and in SQLAnswerA2.sql script file.
Save your SQLAnswerA2.sql file and hand in it together with this paper.

Section Topic Marks Score


A Worksheet 6 30
B Worksheet 7 & 8 28
Page 1 of 15
ISCG 5423 Introduction to Databases (Version A)

C Subquery Exercises 30
D Worksheet 7, 8 & Subquery Exercises 12
Total: 100

Page 2 of 15
ISCG 5423 Introduction to Databases (Version A)

SCENARIO
Description:

The iMusic Company owns a media library website and it needs to maintain
records of its products, music albums, playlists and the customers who buy
each audio track.

Entity Relationship Diagram:

Page 3 of 15
ISCG 5423 Introduction to Databases (Version A)

Relations:

Employee (EmployeeId, LastName, FirstName, Title, ReportsTo*, BirthDate,


HireDate, Address, City, State, Country, PostalCode, Phone, Fax,
Email)
Customer (CustomerId, FirstName, LastName, Company, Address, City,
State, Country, PostalCode, Phone, Fax, Email, SupportRepId*)
Invoice (InvoiceId, CustomerId*, InvoiceDate, BillingAddress, BillingCity,
BillingState, BillingCountry, BillingPostalCode, InvoicePrice)
InvoiceLine (InvoiceLineId, InvoiceId*, TrackId*, UnitPrice, Quantity)
Page 4 of 15
ISCG 5423 Introduction to Databases (Version A)

Track (TrackId, Name, AlbumId*, MediaTypeId*, GenreId*, Composer,


Milliseconds, Bytes, UnitPrice)
Album (AlbumId, Title, ArtistId*)
Artist (ArtistId, Name)
MediaType(MediaTypeId, Name, IsOriginal)
Genre (GenreId, Name)
PlaylistTrack (PlaylistId*, TrackId*)
Playlist (PlaylistId, Name, IsPrivate)

Views:

EmployeeCustomerView (CustomerId, FirstName, LastName, Company,


Address, City, State, Country, PostalCode, Phone, Fax, Email,
SupportRepId, SupportFirstName, SupportLastName,
SupportTitle, SupportAddress, SupportCity, SupportCountry,
SupportEmail, SupportPhone)

Sample Data: Refer to the appendix for sample data.

Note:
For each of the following questions, write SQL statements to accomplish
each of the following tasks and type ALL of your answer in the space
provided in SQLAnswerA2.sql file. Use the expected results given as a
guideline. Save SQLAnswerA2.sql file at the end of the test.

Page 5 of 15
ISCG 5423 Introduction to Databases (Version A)

Section A (Questions on Worksheet 6)

A.1 a. Create a view called GermanyCustomerView, which lists the last name
and city of customers that come from the country of Germany.
b. Display the view. [7
marks]

Expected Result:

A.2 a. Create a view called CountryCustomerView, which lists the billing country
and the average invoice price for each of those countries.
b. Display the view. [8
marks]

Expected Result:

Page 6 of 15
ISCG 5423 Introduction to Databases (Version A)

A.3 Use the EmployeeCustomerView to display the customer id and support rep
full name for each of the customers that live in New York or Mountain View.
The support rep full name is SupportFirstName + ' ' + SupportLastName.
[7 marks]

Expected Result:

A.4 For each support person in the EmployeeCustomerView, display the support
persons last name and the number of customers that support person has
from countries that end with the letter 'a'.
[8 marks]

Expected Result:

Page 7 of 15
ISCG 5423 Introduction to Databases (Version A)

Section B (Questions on Worksheet 7 & 8)

B.1 Display the list of customer's first names and their invoice prices where
price is greater than 18.
[7 marks]

Expected Result:

B.2 For each media type, display the media type's name and the average track
size (in bytes) for that media type.
[9 marks]

Expected Result:

B.3 For each playlist where maximum track size is 11000000 or less, display the
playlist id and the maximum track size (in bytes) for that playlist.
[12 marks]

Expected Result:

Page 8 of 15
ISCG 5423 Introduction to Databases (Version A)

Section C (Questions on Subquery Exercises)

C.1 List the name of the track with the shortest track duration (in milliseconds).
[5 marks]

Expected Result:

C.2 List the emails of customers with invoices where invoice price is greater
than 20. [7 marks]
Note: You MUST use sub-queries to answer this question

Expected Result:

C.3 List the date of the invoices where billing country = Ireland and the invoice
price is higher than the average invoice price. [8 marks]

Expected Result:

C.4 List the support rep id and the invoice date of the invoice with the highest
invoice price.
[10 marks]

Expected Result:

Page 9 of 15
ISCG 5423 Introduction to Databases (Version A)

Section D (Questions on sub-query and inner join exercises)

D.1List the artist names and the titles of the albums made by artists whose
names start with the string 'ac' and the albums contain tracks with a genre
id inferior to 3. [12 marks]

Expected Result:

Page 10 of 15
ISCG 5423 Introduction to Databases (Version A)

APPENDIX - SAMPLE DATA

InvoiceLine

Invoice

Page 11 of 15
ISCG 5423 Introduction to Databases (Version A)

Customer

Employee

Track

Page 12 of 15
ISCG 5423 Introduction to Databases (Version A)

Album

Artist

MediaType

Page 13 of 15
ISCG 5423 Introduction to Databases (Version A)

Genre

PlaylistTrack

Page 14 of 15
ISCG 5423 Introduction to Databases (Version A)

Playlist

EmployeeCustomerView

Page 15 of 15

You might also like