Question

In: Computer Science

Consider the following database schema for a BOOKSTORE database: Books (bookid, title, author, year) Customers (customerid,...

Consider the following database schema for a BOOKSTORE database:

  • Books (bookid, title, author, year)
  • Customers (customerid, name, email)
  • Purchases (customerid, bookid, year)
  • Reviews (customerid, bookid, rating)
  • Pricing (bookid, format, price)

The Books relation stores information about books sold by the bookstore. Note that bookid is the primary key. An example tuple is as follows:

(105, 'JAVA PROGRAMMING', 'JOHN DOE', 2001)

The Customers relation stores information about the customers of the bookstore. Note that customerid is the primary key. An example tuple is as follows:

(210, 'JOHN SMITH', 'SMITH@YAHOO.COM')

The Purchases relation stores information about the customer purchases of books. Note that customerid and bookid form the primary key. An example tuple is as follows:

(210, 105, 2002), indicating that 'JOHN SMITH' with customerid 210 purchased the 'JAVA PROGRAMMING' book with bookid 105 in the year 2002.

The Reviews relation stores information about the customer reviews/ratings of the books. The ratings field refers to the number of "stars" given to the book. Note that customerid and bookid form the primary key. An example tuple is as follows:

(210, 105, 3), indicating that 'JOHN SMITH' with customerid 210 gave a 3-star rating to the 'JAVA PROGRAMMING' book with bookid 105.

The Pricing relation stores information about the price of the various books sold by the bookstore. Note that the same book can be available in multiple formats at possibly different prices. The price field refers to the number of dollars. For instance a $25 purchase will have a price field of 25. Note that the bookid and format fields form the primary key for the relation. An example tuple is as follows:

(105, 'AUDIO', 25), indicating that the 'JAVA PROGRAMMING' book with bookid 105 is available in the audio format for $25.

Given the above schema, write queries for the following:

  1. Find books (show their titles) written by 'EDMUND MORGAN' since year 1990.
  2. Find books (show their titles, authors and prices) that are on 'CIVIL WAR' (i.e., the title field contains 'CIVIL WAR'), available in 'AUDIO' format.
  3. For each year, 'JOHN CHAMBERS' purchased at least one book, find the number of books purchased. That is, the output should be a set of tuples, each indicating a year and the number of books purchased by 'JOHN CHAMBERS' in that year.
  4. Find customers (show their names and email addresses) who purchased more than one book in year 2003.
  5. Find the ratings information (show titles, authors and average ratings) for books on 'CIVIL WAR' (i.e., title contains 'CIVIL WAR').

Solutions

Expert Solution

Table

Drop table Books;
Drop table Customers;
Drop table Purchases;
Drop table Reviews;
Drop table Pricing;
Create table Books(bookid number(4) primary key, title varchar(20), author varchar(20), year number(4));
desc Books;
insert into Books values(105, 'JAVA PROGRAMMING', 'JOHN DOE', 2001);
Select * from Books;
Create table Customers (customerid number(4) primary Key, name varchar(20), email varchar(25));
desc Customers;
insert into Customers values (210, 'JOHN SMITH', 'SMITH@YAHOO.COM');
Select * from Customers;
create table Purchases (customerid number(4) references Customers(customerid), bookid number(4) references Books(bookid), year number(4));
desc Purchases;
insert into Purchases values (210, 105, 2002);
create table Reviews (customerid number(4) references Customers(customerid), bookid number(4) references Books(bookid), rating number(1));
desc Reviews;
insert into Reviews values (210, 105, 3);
Select * from Reviews;
create table Pricing (bookid number(4) references Books(bookid), format varchar(25), price number(10,3));
desc Pricing;
insert into Pricing values(105, 'AUDIO', 25);
Select * from Pricing;

Query:

select title from Books where author='EDMUND MORGAN' and year=1990;


Select Books.title,Books.author,Pricing.price from Books inner join Pricing on Books.bookid=Pricing.bookid where format='AUDIO';


Select year,count(*)"Total Order"from Customers inner join Purchases on Purchases.customerid=Customers.customerid where name= 'JOHN CHAMBERS' group by Purchases.customerid,year;

Select name,email from Customers where customerid in(Select Purchases.customerid from Customers inner join Purchases on Purchases.customerid=Customers.customerid where year=2003 group by Purchases.customerid having count(*)>1);


Select Books.title,Books.author,avg(Reviews.rating) from Books inner join Reviews on Books.bookid=Reviews.bookid where title='CIVIL WAR' group by Books.title,Books.author;

if you still have any Problem regarding this question please comment and if you like my code please appreciate me by thumbs up thank you.........


Related Solutions

Database Schema: Book(bookID, ISBN, title, author, publish-year, category) Member(memberID, lastname, firstname, address, phone-number, limit) CurrentLoan(memberID, bookID,...
Database Schema: Book(bookID, ISBN, title, author, publish-year, category) Member(memberID, lastname, firstname, address, phone-number, limit) CurrentLoan(memberID, bookID, loan-date, due-date) History(memberID, bookID, loan-date, return-date) Members can borrow books from the library. The number of books they can borrow is limited by the “limit” field of the Member relation (it may differ for different members). The category of a book includes fiction, non-fiction, children’s and reference. The CurrentLoan table represents the information about books that are currently checked out. When the book is...
A survey of 77 customers was taken at a bookstore regarding the types of books purchased....
A survey of 77 customers was taken at a bookstore regarding the types of books purchased. The survey found that 46 customers purchased MYSTERIES, 38 purchased SCIENCE FICTION, 32 purchased ROMANCE NOVELS, 20 purchased MYSTERIES AND SCIENCE FICTION, 17 purchased MYSTERIES AND ROMANCE NOVELS, 13 purchased SCIENCE FICTION AND ROMANCE NOVELS, and 6 purchased all three types of books. a). how many of the customers surveyed purchased only mysteries? b). how many purchased mysteries and science fiction, but not romance...
Consider the following schema: Publisher (name, phone, city), PK: name. Book (ISBN, title, year, published_by, previous_edition,...
Consider the following schema: Publisher (name, phone, city), PK: name. Book (ISBN, title, year, published_by, previous_edition, price), PK: ISBN, FK: published_by refs Publisher, previous_edition refs Book. Author (SSN, first_name, last_name, address, income), PK: SSN. Write (aSSN, bISBN), PK: (aSSN, bISBN), FK: aSSN refs Author, bISBN refs Book. Editor (SSN, first_name, last_name, address, salary, works_for, book_count), PK: SSN, FK: works_for refs Publisher. Edit (eSSN, bISBN), PK: (eSSN, bISBN), FK: eSSN refs Editor, bISBN refs Book. Author_Editor (aeSSN, hours), PK: aeSSN, FK:...
Consider the following schema: Publisher (name, phone, city), PK: name. Book (ISBN, title, year, published_by, previous_edition,...
Consider the following schema: Publisher (name, phone, city), PK: name. Book (ISBN, title, year, published_by, previous_edition, price), PK: ISBN, FK: published_by refs Publisher, previous_edition refs Book. Author (SSN, first_name, last_name, address, income), PK: SSN. Write (aSSN, bISBN), PK: (aSSN, bISBN), FK: aSSN refs Author, bISBN refs Book. Editor (SSN, first_name, last_name, address, salary, works_for, book_count), PK: SSN, FK: works_for refs Publisher. Edit (eSSN, bISBN), PK: (eSSN, bISBN), FK: eSSN refs Editor, bISBN refs Book. Author_Editor (aeSSN, hours), PK: aeSSN, FK:...
Consider the following universal relation THE following database schema is in 4NF. What can you infer...
Consider the following universal relation THE following database schema is in 4NF. What can you infer about multi-valued dependencies? A C D A B C E E F A-It does not have multi-valued dependencies. B-The multi-valued dependency A ->-> C does not hold. If the multi-valued dependency A ->-> C held, the database would not be in 4NF. C-The multi-valued dependency A ->-> B does not hold. If the multi-valued dependency A ->-> B held, the database would not be...
Consider the following database schema:                Product(maker, model, type)                PC(model, speed
Consider the following database schema:                Product(maker, model, type)                PC(model, speed, ram, hd, rd, price)                Laptop(model, speed, ram, hd, screen, price)                Printer(model, color, type, price) Give SQL statement for each of the following: (Grouping and Aggregation) Write the following queries in SQL: Find the average speed of laptops costing over $2000. Find the average price of PC’s and laptops made by manufacturer “D”. Find, for each manufacturer, the average screen size of its laptops. Find the manufacturers...
Consider the following database schema:                Product(maker, model, type)                PC(model, speed
Consider the following database schema:                Product(maker, model, type)                PC(model, speed, ram, hd, rd, price)                Laptop(model, speed, ram, hd, screen, price)                Printer(model, color, type, price) Give SQL statement for each of the following: (Subqueries, Join operations) Write the following queries in SQL: Find the makers of PC’s with a speed of at least 1200. Find the printers with the highest price. Find the laptops whose speed is lower than that of any PC. Find the model number...
SQL query exercises: Consider the following database schema:                Product(maker, model, type)              &
SQL query exercises: Consider the following database schema:                Product(maker, model, type)                PC(model, speed, ram, hd, rd, price)                Laptop(model, speed, ram, hd, screen, price)                Printer(model, color, type, price) Consider the Drivers-Cars-Reserves DB for a small rental car company:                Drivers(id, name, rating, age)                Cars(vin, maker, model, year, color)                Reserves(did, vin, date) Give SQL statement each of the following operations: Find the colors of cars reserved by Smith. Find all id’s of drivers who have a...
Question 2: consider the following library relational database schema Write a program segment to retrieves the...
Question 2: consider the following library relational database schema Write a program segment to retrieves the list of books that became overdue yesterday and that prints the book title and borrower name for each. 1- Use JDBC with Java as the host language
[Q.4] Answer the following questions You are invited as a database architect to develop database schema...
[Q.4] Answer the following questions You are invited as a database architect to develop database schema for maintaining patient information for the NYU medical group (make necessary assumptions for the data requirements if needed). Each physician in the Lehman medical group is uniquely identified by physicianID o Each physician must have first name, and last name, and phone number Each patient is identified by patientID o Each patient must have first name, and last name, phone number, and insurance card...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT