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

Tutorial_5_Question_paper_of_SQL_exercise

The document outlines SQL exercises for a course on Database Management Systems, focusing on a restaurant schema. It includes simple, insert/delete, and complex query tasks related to restaurant data, member information, and visit records. The exercises require the use of provided SQL scripts for table creation and data loading, along with specific SQL queries to retrieve and manipulate data based on given criteria.

Uploaded by

wzy190817
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)
5 views

Tutorial_5_Question_paper_of_SQL_exercise

The document outlines SQL exercises for a course on Database Management Systems, focusing on a restaurant schema. It includes simple, insert/delete, and complex query tasks related to restaurant data, member information, and visit records. The exercises require the use of provided SQL scripts for table creation and data loading, along with specific SQL queries to retrieve and manipulate data based on given criteria.

Uploaded by

wzy190817
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/ 2

COMP3278 Introduction to Database Management Systems

2024 – 2025

SQL exercises
This exercise uses the following schema.
Restaurant (restaurant_id, name))

RestaurantCategory (restaurant_id, category)


Foreign key: {restaurant_id} references Restaurant

Branch (restaurant_id, branch_no, location, seats)


Foreign key: {restaurant_id} references Restaurant

Member (member_id, name, birthday, joined, points)


(joined is the year the member joined)

visits (visit_id, member_id, restaurant_id, branch_no, date, score)


Foreign keys: {restaurant_id, branch_no} references Branch,
{member_id} references Member
Hints: You can use the provided scripts with `source sql_tables.sql` and `source sql_data.sql` to
create tables and load data. You should firstly upload the sql file to the server with `scp`.
If you use your own MySQL, you can create a new database, otherwise please set the database in
sql_tables.sql when using HKU MySQL.

Give a SQL for each of the followings.

Simple queries

1. List the name, the number of branches, and the average number of seats of all
restaurants, order by the restaurant name.

2. List the name and location of all fast food joints (category “Fast Food”), order the list by
the restaurant name and then by the branch location.

3. Find the members whose name starts with ‘A’ or ‘E’. List the results by showing the
member name and the birthday, order by the member name.

4. Find all restaurant branches located in the central (i.e., location with “Central”), list only
the restaurant name, the branch location, and the number of seats. Order the list by the
number of seats, then by the location. Show only the first 2 results.
Insert/delete queries

5. Add 10 points per year joined to every member. The current year is 2025. For example, if
a member joined in year 2010, 150 points should be added. (The joined field stores the
year the member joined the membership)

6. Insert a new member whose name is “Albert B. Carter” and born on “1985-07-25”, with
100 points, with member_id equals 300, joined the membership in year 2018.

7. Remove all visiting records before year 2016.

Complex queries

8. Find all branches with at least one visit scoring less than 4. List the restaurant name, the
branch location, and the best score among the visits to the branch. Order the list by the
restaurant name, and then the location.

9. Find all members who has visited the restaurant branch(/branches) that received the
lowest average score ever. Show only the member name, order by the member name.

10. Find all members who have made at least two visits, show only the member name, the
name of the restaurant of the member’s first visit, and that of the last visit. Show any of
the restaurant names if the member visited more than one restaurant on the same day.
Order the list by the member name. Show only the first 5 results.

11. Count the number of unique members visiting each of the restaurants. List the result by
showing the restaurant name, and the number of members. A restaurant should be
listed even if it is not visited by any member, in that case the count should be zero. Order
the list by the number of unique members (descending), then by restaurant name.

You might also like