Question

In: Computer Science

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 of types of Publisher and Category fields? For example, if you knew there were 3 types of Publisher and 4 types of Category, how many groupings would you expect?

Solutions

Expert Solution

1.SELECT COUNT(Publisher) AS No_of_Publisher, (SELECT COUNT(Category) FROM Book GROUP BY Category) AS No_Of_category

FROM Book GROUP BY Publisher;

EXPLANATION:-

Here, SELECT is used to fetch the data from the table.

COUNT() is used to calculate the rows from the table.

We are getting count of publisher in main query and getting count of category in the sub query .

Grouping is done to calculate the number of distinct category and Publishers.

2. SELECT COUNT(Distinct_Row ) AS No_Of_Grouping FROM (

SELECT Distinct Publisher,Category,"Row" as Distinct_Row FROM

Book ) ;

EXPLANATION:-

Here , we are getting combined grouping of category and Publisher.

In sub query we fetch the distinct pairs of publisher and category from the Book table .

In SELECT we add one more column with Row as input.

In main query we calculate the number of distinct publisher and category pair using the Distinct pairs .

This gives us number of groupings currently we have.


Related Solutions

3. (12) Amazon had a public dispute with the book publisher Hachette regarding its prices for...
3. (12) Amazon had a public dispute with the book publisher Hachette regarding its prices for e-books. Amazon was trying convince Hachette to lower their price for e-books, arguing that doing so would benefit both consumers and the publisher; Hachette was refusing to cut their prices, countering that lower prices would hurt both the publisher and their authors. Amazon explained their objectives in terms of price elasticity on their discussion board which they recently discontinued. The full post was e-mailed...
Write the SQL DDL to create the following 5 tables for an App store: Publisher, Category,...
Write the SQL DDL to create the following 5 tables for an App store: Publisher, Category, App, AppVersion, AppVersionReview: A Publisher table where each publisher is identified by an integer id and has a name (up to 40 characters). (1 mark) A Category table where each category has an id (integer), a name (up to 50 characters), and a parentId to identify its parent category. The parentId should be a foreign key to the Category table. (1.5 marks) An App...
Amazon had a public dispute with the book publisher Hachette regarding its prices for e-books. Amazon...
Amazon had a public dispute with the book publisher Hachette regarding its prices for e-books. Amazon was trying convince Hachette to lower their price for e-books, arguing that doing so would benefit both consumers and the publisher; Hachette was refusing to cut their prices, countering that lower prices would hurt both the publisher and their authors. Amazon explained their objectives in terms of price elasticity on their discussion board which they recently discontinued. The full post was e-mailed to the...
DEFINE the listed types of retails and the wholesalers? Convenience Retailer Discount Retailer Category Specialists Off-Price...
DEFINE the listed types of retails and the wholesalers? Convenience Retailer Discount Retailer Category Specialists Off-Price Retailers ---- Merchant Wholesalers Merchandise Agent/Brokers
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...
3. The net price of a table is RM1,600.A trade discount of 10% is offered. Find...
3. The net price of a table is RM1,600.A trade discount of 10% is offered. Find the list price. 5. Mariam paid RM239.29 for a bag that was offered a chain discount of 15% and 8%.What was the list price of the bag? 7. Kinta Trading sells an item for RM90 less 25% and 10%.Softee Trading sellsthe same item for RM100 less 30%. (a)Find the net prices of the item for the two companies. (b) What additional discount percentage must...
Consolidation at date of acquisition (purchase price greater than book value, acquisition journal entries Assume that...
Consolidation at date of acquisition (purchase price greater than book value, acquisition journal entries Assume that the parent company acquires its subsidiary by exchanging 84,000 shares of its $2 par value Common Stock, with a fair value on the acquisition date of $39 per share, for all of the outstanding voting shares of the investee. In its analysis of the investee company, the parent values all of the subsidiary’s assets and liabilities at an amount equaling their book values except...
I have a table of bike riders in the following format: Bike_number, Start_date(date and time), End_date(date,...
I have a table of bike riders in the following format: Bike_number, Start_date(date and time), End_date(date, time) I also have a table of temperatures per hour Using sql: how do I calculate Count/min/max/average of riders as compared to the temperature at the hour
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 limit order book for a share of stock. Bid Ask Price Shares Price...
Consider the following limit order book for a share of stock. Bid Ask Price Shares Price Shares $79.75 500 $79.80 500 79.70 900 79.85 400 79.65 700 79.90 900 79.60 1000 79.95 700 78.65 600 a. If a market sell order for 1200 shares comes in, at what price(s) will it be filled? from low to high b. Immediately after the order in a) is executed, what is the bid-ask spread of the stock? (Keep two decimal places.)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT