Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Assume the same database as in Homeworks 1 and 2 : - BOOK (isbn, title, num-pages, publisher, year, genre, price, aut-id). The first attribute is

image text in transcribed

image text in transcribed

Assume the same database as in Homeworks 1 and 2 : - BOOK (isbn, title, num-pages, publisher, year, genre, price, aut-id). The first attribute is the primary key; the last one is a foreign key to AUTHOR. - CUSTOMER (customer-id, name, address, city, state, zip, age). The first attribute is the primary key. - Sales (isbn, custid, num-copies, day, month, year, total). The first attribute is a foreign key to BOOK and the second a foreign key to CUSTOMER. The key of this table is the two foreign keys together. - AUTHOR (author-id, name, dob, nationality, address, city, state, zip). The first attribute is the primary key. 2. Write the following questions in SQL. 1 (a) List the name and address of customers who have bought both a sci-fi book and a romance book (recall that 'sci-fi' and 'romance' are values of genre). (b) List the name and address of customers who have bought at least two different books (not two copies of a book). (c) List the name and address of customers who have never bought a sci-fi book. (d) List the name and address of customers who have bought the most expensive book in the database (note: there can be several such books; buying any one of them is enough). (e) For each customer, give the name and total amount of money spent (the money spent on each sale is given by total). (f) For each state, find the total amount of money spent by customers on that state, but only if the state has at least 10 customers. (g) Find the top 10 best customer (where 'best' is defined by having bought the largest number of books. Note that a customer may buy more than one copy of each book, but here we are just asking about books). (h) The popularity of a book is the number of customers who have bought that book. Calculate the average popularity of all books. EXTRA CREDIT: find the titles of books which are more popular than the average

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beyond Big Data Using Social MDM To Drive Deep Customer Insight

Authors: Martin Oberhofer, Eberhard Hechler

1st Edition

0133509796, 9780133509793

More Books

Students also viewed these Databases questions