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.

1. List the titles of books published by MIT Press in 2016 that have sold during the month of May to a customer from KY. 2. List the names of customers who have bought a horror book or a sci- book. 3. List the names of customers who have bought a horror book and a sci- book. 4. List the title of books who have never been sold to a customer in KY. 5. List the titles of books who have only been sold to customers in KY. 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!