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.
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...
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...
Write the following queries using the schema below Class (Number, Department, Term, Title) Student (Username, FirstName,...
Write the following queries using the schema below Class (Number, Department, Term, Title) Student (Username, FirstName, LastName, Year) Takes (Username, Department, Number, Term, Grade) [clarification] In Student, Year is an integer. A student can be a 2nd year student. In that case, Year value would be 2. For the Takes relation: ·         Grade is NA for current semester students ·         Username is foreign key to Student ·         (Department, Number, Term) is foreign key to Class a)       Write an SQL query that returns the Term...
Q17    The following data relate to a popular book sold by a publisher: Fixed Costs: Copy Editing...
Q17    The following data relate to a popular book sold by a publisher: Fixed Costs: Copy Editing $ 6,110 Artwork $ 2,250 Typesetting $ 70,853 Variable Costs per copy: Printing and Binding $ 3.17 Bookstore Discounts $ 4.14 Sales Commissions $ 0.59 Author’s Royalties $ 2.44    Each novel copy sells for $ 24 Last month the company sold in copies: 10,771 Production manager suggests to buy an additional machine for $5,250 cost per month and will decrease the variable cost...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT