0% found this document useful (0 votes)
4 views

Assignment 2

The document outlines Assignment 2 for the CS3402 Database Systems course at City University of Hong Kong, focusing on SQL and relational algebra queries related to an online media subscription database. It includes tasks such as retrieving media titles, author information, membership details, and access records. Additionally, it specifies that submissions must be made through a designated online platform rather than Canvas.

Uploaded by

LL 3708
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Assignment 2

The document outlines Assignment 2 for the CS3402 Database Systems course at City University of Hong Kong, focusing on SQL and relational algebra queries related to an online media subscription database. It includes tasks such as retrieving media titles, author information, membership details, and access records. Additionally, it specifies that submissions must be made through a designated online platform rather than Canvas.

Uploaded by

LL 3708
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Department of Computer Science, City University of Hong Kong

CS3402 Database Systems


Assignment 2
================================================================
Question A SQL. [60 points]

Given the following database about the information of an online media subscription website.
It structures the management of authors, publishers, members, media items (including music,
movies, books, etc.), memberships, subscriptions, and access records.

 Author (social_id: integer, name: string, gender: string)


// Contains information about authors, including their social ID, name, and gender.
 Publisher (register_id: integer, name: string, country: string)

// Contains information about publishers, including their registration ID, name, and
country.
 Member (member_id: integer, name: string, gender: string, nationality: string, email:

string)
// Contains information about members, including their member ID, name, gender,
nationality, and email.
 Media (media_id: integer, type: string, title: string, author: integer, publisher: integer)

// Contains information about media items, including their media ID, type (e.g., book,
movie, music), title, author (refer to Author. social_id), and publisher (refer to Publisher.
register_id).
 Membership (type: string, price: integer, discount: float)

// Contains information about membership types, including type name, price, and discount
rate.
 Subscription (membership: string, member: integer, start_date: date, expire_date:

date)
// Contains records indicating which members subscribe to which type of membership,
including membership (refer to Membership.type), member ID (refer to
Member.member_id), start date, and expiration date.
 AccessRecord (media: integer, member: integer, datetime: date)

// Contains records indicating which customers access which media on which date,
including media ID (refer to Media.media_id), member ID (refer to Member.member_id),
and the date of access.
(Note: For Question A, you need to log into http://dboj.cs.cityu.edu.hk:8080/ and choose
SQL Homework 2 under Exercise to answer the questions for the online judge. Submissions
directly made to Canvas will not be graded.)

-- 1. List the titles of all 'book' type media which are written by male authors. [6 points]
-- 2. Find the names of all authors who have NEVER published a media with UK publisher.
[6 points]

-- 3. List all the US publishers and the total number of media they have published. Order the
results in DESCENDING order of the total number of media. [6 points]

-- 4. List the types of the memberships and its members amount. Sort the members amounts
in ASCENDING order, and do not list memberships which has less than 2 members. [6
points]

-- 5. Calculate the average revenue from each subscriptions that started between '2025-01-01'
and '2025-12-01' (including both endpoints). Assume that all payments are made on the start
date of the subscription, and the discount rate for each membership has not changed since
'2025-01-01'. Hint: Consider discount and use the 'YYYY-MM-DD' format to represent a
date. [6 points]

-- 6. List all nationalities along with the total number of ‘movie’ Access Record from each
nationality. [6 points]

-- 7. Get the emails of all members who have accessed all kinds of media, after 2025-01-01.
[6 points]

-- 8. Find the names of the members who have subscribed to two different kinds of
subscriptions [6 points]
-- 9. List the names of the members who have active 'Premium' membership (meaning their
membership expires on or after today) but have never accessed to any type of media.
Asuming today is '2025-03-01'. [6 points]

-- 10. Return the distinct IDs of the publisher whose media have been accessed most times by
members. If more than one publisher has this maximum total, list all of them. [6 points]

Question B Relational Algebra [40 points]


Solve all queries below on the COMPANY schema using relational algebra
expressions (Note: No score will be given for SQL). Write the result of each
query applied to the database state in Figure 5.6. (Note that the result can be an
empty set.)
(1) Retrieve the full names of male managers. [4 marks]

(2) Retrieve the addresses of all employees whose department location is Stafford and

whose salary is no more than 25000. [4 marks]


(3) Retrieve the salary of all managers who don’t have children. [8 marks]

(4) List the birthdates of all female managers, and the birthdates of all female dependents

of all managers in one table. [8 marks]

(5) List the names of the departments where employees who work on both the

Computerization and the Newbenefits projects are located. [8 marks]

(6) Find the last names of employees in department No.5 who don’t work in Bellaire. [8

marks]

You might also like