Lab 8 - SQL Aggregate Functions
Lab 8 - SQL Aggregate Functions
Remove all tables from your database schema and run the script book_shop_data.sql files to
create the tables below. You may use the book_shop_cleanup.sql to remove the tables
when you are done.
INFS2201 – Database Management Systems
Note
Some of the questions may require more than one SQL query to complete. Provide the
query (queries) and the first few rows of the result set as a screenshot as shown in lab.
Take this file, insert your name and ID at the top, then for each question, run your query in
MySQL Workbench and take a screenshot that shows your DB name on the left pane, your
query, and a few lines of the output. Insert the screenshot under the relevant question in
Word, then Save As or Export it to PDF and upload to D2L.
Question 1
Write a function that returns the number of books in the table with the author number 501.
Question 2
Write a function that summarizes the number of books in the store that are published by
publisher number 60, and publisher number 180. Make the result set header to be
“publisher” and “quantity” (the numbers below are just examples, your data will be
different:
Question 3
Write a query that tells you how many authors had their books published by publisher
number 50. Make sure the result header to “total.”
Question 4
Write one query that tells lists the author IDs who have exactly 6 books in the database.
Question 5
Write a query that tells which customers have completed two orders. You will know that a
shopping cart was ordered if the “ordered” field has a time recorded. The output of this
query should be just the customer IDs.
Question 6
Using a sub-query produce a list of the books titles whose publishers have a URL that ends
with ‘.com’ and sort the output alphabetically from A to Z.
INFS2201 – Database Management Systems
Question 1
List the warehouse id and the total number of books they have for the warehouse locations
that have more than 120000 books in stock. Use the column headers warehouse and
total_books
Question 2
Update warehouse 2 to make ensure that any book they have with a quantity of less than
50, be increased by 100 copies. Then run the query from question 1 (part 2) above which
should show both warehouses now.
Question 3
Find how many books are in the book table that were never purchased. This will be a single
number and requires a sub-query.
Question 4
How many books has Llyod Rust purchased? The answer must use sub-querie(s). The query
must also work for all cases for full marks.
Grading Rubric
Each problem is worth 2 points. Your instructor will award either 0, 1 or 2 based on the
correctness.