Assignment 2
Assignment 2
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.
// 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]
(2) Retrieve the addresses of all employees whose department location is Stafford and
(4) List the birthdates of all female managers, and the birthdates of all female dependents
(5) List the names of the departments where employees who work on both the
(6) Find the last names of employees in department No.5 who don’t work in Bellaire. [8
marks]