Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You are presented with the following database. Please pay attention to all primary and foreign keys as it will effect your answer. Please write

You are presented with the following database. Please pay attention to all primary and foreign keys as it will effect your answer.

image text in transcribed\

Please write the following queries in SQL and ensure they compile the right results, Thank you I will upvote!

image text in transcribed

INSTRUCTIONS: Read what follows carefully. Make sure you understand the structure of the database. Make sure you understand what each question is asking. If you need any clarifications, email the instructor ASAP. Please note: it's ok to ask clarifications on any question or any aspect of SQL, but please do not send an answer and ask "is this ok?". Assume the same database as in Homework 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. Attribute dob stands for 'date of birth'. Attribute nationality has values like 'British', 'Australian', etc. Attribute genre has values like 'sci-fi', 'romance', etc. Note that this schema assumes that each book has one and only one author, but it can be sold to different customers at different times. Write the following queries in SQL: 1. List the title and publisher of all the books that have been sold to a customer from the state of Kentucky. 2. List the name and address of authors who have written a sci-fi book and a romance book. 3. List the name and address of authors who have never written a sci-fi book. 4. List the name and address of authors who have written at least two books. 5. List the title and author's name of each book whose price is above the average price (of all books). 6. For each state, find the total amount of money spent by buyers from that state (the money spent on each sale is given by total). 7. For each author, find the total number of copies sold of all the book's authors, but only for authors with at least 5 books. 8. Find the 10 most prolific authors (i.e. the 10 authors that have authored the largest number of books)

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

Practical Neo4j

Authors: Gregory Jordan

1st Edition

1484200225, 9781484200223

More Books

Students also viewed these Databases questions

Question

What is the growth rate of GDP per capita?

Answered: 1 week ago