Question: Write the following questions as queries (SELECT statements) in SQL. Use only the operators discussed in class (SELECT, FROM, WHERE, GROUP BY, HAVING, CASE, subqueries).
Write the following questions as queries (SELECT statements) in SQL. Use only the operators discussed in class (SELECT, FROM, WHERE, GROUP BY, HAVING, CASE, subqueries). You cannot use LIMIT or window functions (not that they are needed). Type your answers and format your queries.
The following database schema is given:
BOOK(isbn,title,num-pages,publisher,year,genre,price)
CUSTOMER(custid,name,address,city,stake,zip,age)
SALES(isbn,custid,num-copies,day,month,year)
Attribute isbn in SALES is a foreign key to BOOK. Attribute custid is a foreign key to CUSTOMER. Note that a book may have been sold to several customers, and customers may buy several books (thats why the key for SALES is (isbn,custid)). Note that year in BOOK is the year the book was published, year in SALES refers to the date of a particular sale. genre in BOOK describes the type of narrative, like sci-, history, romance, technical.
6. List the names of customers who have made a single purchase.
7. Find the title of the most expensive book(s) in the whole database.
8. Find out the total income (number sold times price) per book for all sci- books.
9. Find the zip code(s) with the most customers.
10. Find the number of customers from KY that have not bought any sci- books (but they bought some book).
11. List the titles of books that have sold more copies in 2015 than in 2016.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
