Question

In: Computer Science

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: aeSSN refs Author, aeSSN refs Editor.

Give SQL statements for the following plain English language queries based on the above schema.

Hint: You may use views to hold intermediate results.

  1. Show the number of books published in 2008 versus the number of books published in 2009 for every publisher. The result should have the following four columns: publisher_name, book_count_08, book_count 09, percentage of increase from 2008 to 2009

2. Provide an SQL UPDATE statement that updates the book_count field of the Editor table by computing the number of books edited by each editor using nested queries. (10 pts)

3. For each publisher, find the title of the book that it publishes with the largest number of editors. The output should have two columns - one is the publisher’ name and the other is the title of the book found.

Solutions

Expert Solution

Answer to Question 1

We are using correlated sub queries to find the solution. There are two sub queries and both will be joined.

SELECT sub8.Publisher_Name, sub8.book_count_08, sub9.book_count_09, ( (sub9.book_count_09-sub8.book_count_08)/sub9.book_count_09) * 100 AS [Percentage_Increase from 08 to 09] FROM

(SELECT published_by AS Publisher_Name,COUNT(ISBN) AS book_count_08 FROM Book

WHERE year=2008 GROUP BY published_by) As Sub8

LEFT JOIN

(SELECT published_by AS Publisher_Name,COUNT(ISBN) AS book_count_09 FROM Book

WHERE year=2009 GROUP BY published_by) AS sub9

ON sub8.Publisher_Name=sub9.Publisher_Name

Answer to Question 2

The nested query to update the table is as follows:

UPDATE editor SET book_count=sub.book_count (

SELECT eSSN,count(bISBN) AS Book_Count

) SUB

WHERE SSN=sub.eSSN;

Answer to Question 3

SELECT published_by,title FROM

SELECT p.published_by,p.title,MAX(count(e.eSSN)) AS Count FROM book b INNER JOIN edit e ON b.ISBN=e.bISBN

GROUP BY p.published_by,p.title)


Related Solutions

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:...
The most common attributes of a book are the Book Title, and ISBN. The most common...
The most common attributes of a book are the Book Title, and ISBN. The most common functions are to set the Book Title, and ISBN, Write the code to implement this problem. 1. Write the UML Diagram that represents this class Book 2. Use code blocks editor and in C++ Write a header file Book with these properties. Write the implementation file for the member functions.
Add the following private attributes: String publisher String title String ISBN String imageName double price Create...
Add the following private attributes: String publisher String title String ISBN String imageName double price Create getter/setter methods for all data types Create a constructor that takes in all attributes and sets them Remove the default constructor Override the toString() method and return a String that represents the book object that is formatted nicely and contains all information (attributes) In the main class: Create a main method that throws FileNotFoundException Import java.io libraries Import java.util.Scanner Create a loop to read...
Consider the following database schema: Frequents(kid, store) Sells(store, candy) Likes(kid, candy) Stores(store, city, phone) Kids(kid, city,...
Consider the following database schema: Frequents(kid, store) Sells(store, candy) Likes(kid, candy) Stores(store, city, phone) Kids(kid, city, age) Write relational algebra expression(s) to: a) Find the stores in ’Warrensburg’, for each display only the store name and phone number. b) Find the stores in ’Warrensburg’, which sells ’Hersheys’ or ’Mars’. Your expression must use set union. c) Repeat the above without using set union. d) Find the kids who are 10 years or older and like ’M&Ms’. e) Find the kids...
Consider the following relational database schema:             employee(employee-name, employee-id, street, e-city)             works(employee-
Consider the following relational database schema:             employee(employee-name, employee-id, street, e-city)             works(employee-id, company-id, salary)             company(company-name, company-id, c-city)             manages(employee-id, manager-id) Specify the following queries on this database schema using the relational operators we discussed in class. Write your answers on a separate sheet of paper in the order that they are specified below. Retrieve the name and address of employees who work for First Bank Corporation. Retrieve the name, street address, and city of residence of all employees...
Using textbook Title Introductory Financial Accounting for Business Author Edmonds, Christopher T. ISBN 978-1-260-81444-6 Publisher McGraw-Hill...
Using textbook Title Introductory Financial Accounting for Business Author Edmonds, Christopher T. ISBN 978-1-260-81444-6 Publisher McGraw-Hill Education Publication Date January According to GAAP, uncollectible receivables must be estimated and recorded as an expense in the period in which the corresponding revenue is earned. This ensures compliance with the matching principle. (1) Compare and contrast the percent of revenue method and the percent of receivables method. (2) Why would a financial manager or analyst be concerned if the Allowance for Doubtful...
A comic book publisher must meet the following demand for a popular comic book on time...
A comic book publisher must meet the following demand for a popular comic book on time or risk long term loss of revenue as schools change to another comic: quarter 1-60,000; quarter 2-40,000; quarter 3-50,000; quarter 4-15,000. The comic can be printed for $25 with regular-time labor and for $35 with overtime labor. At most 30,000 comics can be printed with regular-time labor in a single quarter. The publisher currently has 5,000 comics on hand. It costs $4 per quarter...
Link the following two tables: HumanResources.Employee and Sales.SalesPerson then display Employee PK, job title, Date of...
Link the following two tables: HumanResources.Employee and Sales.SalesPerson then display Employee PK, job title, Date of birth, Gender, Sales quotas, Commission percent and bonus. Use an outer join to display all the employee whether they are in sales or not. Make sure to sort by bonus desc. Explain why some of the field from the Sales.SalesPerson table are null.
SQL 9. Link the following two tables: HumanResources.Employee and Sales.SalesPerson then display Employee PK, job title,...
SQL 9. Link the following two tables: HumanResources.Employee and Sales.SalesPerson then display Employee PK, job title, Date of birth, Gender, Sales quotas, Commission percent and bonus. Use an outer join to display all the employee whether they are in sales or not. Make sure to sort by bonus desc. Explain why some of the field from the Sales.SalesPerson table are null.
Imagine a Book table that had the following: Book Table BookId Category Price Discount Publisher Date...
Imagine a Book table that had the following: Book Table BookId Category Price Discount Publisher Date Next, let's say you had to group by Publisher and Category while retrieving the total price and total number of rows within that grouping. 1. Write the SQL to figure out how many types of Publisher values and Category values there are. 2. How would you write an equation to demonstrate the number of groupings you would expect if you knew the exact number...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT