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.

  • Provide the title, year, and publisher name of every book and the first name and last name of the editor of the book.
  • Provide the title of those books whose author’s last name is neither “Smith” nor “Doe”.
  • Provide the first name and last name of every author-editor who edits at least one book that is written by him or herself.
  • Provide the title of the most expensive book published by the publisher named “ABC”.
  • Provide the first name and the last name of those editors who have edited all the books written by John Smith.
  • Give the title of those books that have more than 3 authors.
  • 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

  • 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.
  • 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.
  • Provide the name of each publisher that is located in ‘OKC’ and is one of the top three publishers in terms of the total amount of salary it pays its editors.

Solutions

Expert Solution

1. Provide the title, year, and publisher name of every book and the first name and last name of the editor of the book.

SELECT title, year, Published_by from Books
UNION
SELECT FirstName, LastName from Editor;

2.Provide the title of those books whose author’s last name is neither “Smith” nor “Doe”.

SELECT ISBN from Author

WHERE LastName != 'Smith', 'Deo' IN ( SELECT title from Book

WHERE ISBN = '1' ,'2' ,'3');

3.Provide the first name and last name of every author-editor who edits at least one book that is written by him or herself.

SELECT FirstName, LastName from Editor
WHERE ( aeSSN = eSSN);

4.Provide the title of the most expensive book published by the publisher named “ABC”.

SELECT MAX(price) as max_price from

WHERE (Published_by = 'ABC');

5.Provide the first name and the last name of those editors who have edited all the books written by John Smith.

SELECT FirstName, LastName from (
SELECT ISBN from Books
UNION ALL
SELECT bISBN from Editor)
WHERE ( ISBN = bISBN);

6.Give the title of those books that have more than 3 authors.

SELECT
FirstName,
ISBN,

COUNT (*) occurrences
from Author

GROUP BY
FirstName,
ISBN,

Select Book.title
from Book;

7.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

SELECT COUNT(year) from Book
WHERE year = 2008
UNION
SELECT COUNT(year) from Book
WHERE year = 2009
SELECT year, count() * 100.0 / (SELECT count () from Book);

8.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.

SELECT Bookcount from Editor
WHERE Bookcount INENTITY (1,1);

9.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.

SELECT
published_by,
Works for,

COUNT(*) occurrences
from Book

GROUP BY
published_by,
Works for,

SELECT Book.title,
Book.published_by
From Book;

11.Provide the name of each publisher that is located in ‘OKC’ and is one of the top three publishers in terms of the total amount of salary it pays its editors.

SELECT name from publisher WHERE ( city = 'OKC')

UNION

SELECT name from editor
WHERE IN ( SELECT eSSN, MAX(salary) as max_salary from Editor )
GROUP BY salary;


Related Solutions

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...
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.
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...
In java Implement the class Book. It has the following instance variables: name, subject, year, maximumLoanPeriod,...
In java Implement the class Book. It has the following instance variables: name, subject, year, maximumLoanPeriod, and loanPeoriod. The following methods should be included: • Constructor(s), Accessors and Mutators as needed. • public double computeFine() => calculates the fine due on this item The fine is calculated as follows: • If the loanPeriod <= maximumLoanPeriod, there is no fine on the book. • If loanPeriod > maximumLoanPeriod o If the subject of the book is "CS" the fine is 10.00...
Consider the following data: Year 1 Year 2 Year 3 Year 4 Book Value of Equity...
Consider the following data: Year 1 Year 2 Year 3 Year 4 Book Value of Equity 25 ROE 22% 22% 30% 30% Payout 65% 65% 60% 60% Net Income Dividends Retained Earnings g - a) Complete the table. b) Check that in period 2 and period 4, the dividends grow according to the formula: g = ROE (1 - Payout) and explain. c) Determine the value of equity (E), taking into account that the dividend growth rate after the 4th...
Consider the following relational schema about a University (the primary keys are underlined and foreign keys...
Consider the following relational schema about a University (the primary keys are underlined and foreign keys are italic) STUDENT(StudentID, name, major, year, age) CLASS(ClassName, meetsAt, room, LecturerID) ENROLLED(StudentID, ClassName, mark) LECTURER(LecturerID, name, DepartmentID) DEPARTMENT(DepartmentID, name) Write the SQL statements for the following query: B1. Find the age of the oldest student. B2. Find the ID’s of lecturers whose name begins with “K” \ B3. Find the age of the youngest student who is enrolled in Mechatronics. B4. Find the age...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT