BuyFindarrow_forward

Database Systems: Design, Implemen...

12th Edition
Carlos Coronel + 1 other
Publisher: Cengage Learning
ISBN: 9781305627482

Solutions

Chapter
Section
BuyFindarrow_forward

Database Systems: Design, Implemen...

12th Edition
Carlos Coronel + 1 other
Publisher: Cengage Learning
ISBN: 9781305627482
Chapter 8, Problem 65P
Textbook Problem
89 views

Write a query to display the book number, title, subject, average cost of books within that subject, and the difference between each books cost and the average cost of books in that subject. Sort the results by book title. (Figure P8.65)

FIGURE P8.65 BOOKS WITH AVERAGE COST BY SUBJECT

Chapter 8, Problem 65P, Write a query to display the book number, title, subject, average cost of books within that subject,

Program Plan Intro

SELECT statement:

It is used to retrieve information from the table or database. The syntax for the “SELECT” statement is given below:

Syntax:

SELECT * FROM table_Name;

“Round()” function:

This function is used to round a number that specified in decimal places. The format of the “Round()” function is as follows:

Syntax:

ROUND(number, decimal_places)

AVG function:

  • • It is one function of the aggregate function.
  • • This function is used to get the average of all the values from the column.
  • Syntax: SELECT AVG(column_Name) FROM table_Name;

INNER JOIN keyword:

“INNER JOIN” keyword is used to select all the matching records of both the table.

Syntax:

SELECT col_Name FROM table_Name1 INNER JOIN table_Name2 ON table_Name1.col_Name = table_Name2.col_Name;

“GROUP BY” Clause:

The GROUP BY clause is used to group the result of a SELECT statement completed on a table where the values of tuple are identical for more than one column.

Syntax:

SELECT expression1, expression2, expression_n, aggregate_function (expression)FROM table_name WHERE conditions GROUP BY expression1, expression2, expression_n;

ORDER BY Clause:

SQL contains “ORDER BY” clause in order to sort rows. The values get sorted in ascending as well as descending order. The keyword used to sort values in ascending order is “ASC” and for descending order is “DESC”. By default, it sorts values by ascending order.

Syntax:

SELECT column_Name1, column_Name2 FROM table_Name ORDER BY column_Name2;

Explanation of Solution

Query to display the given details for the corresponding condition:

The query to display the given details for the corresponding condition is given below:

SELECT BOOK_NUM, BOOK_TITLE, book.BOOK_SUBJECT,

ROUND(averageCost,2) AS "AVGCOST", Round(BOOK_COST-averageCost,2) as "DIFFERENCE"

FROM BOOK INNER JOIN (SELECT AVG(BOOK_COST) AS averageCost , BOOK_SUBJECT FROM BOOK GROUP BY BOOK_SUBJECT) averageCalc ON

averageCalc.BOOK_SUBJECT = book.BOOK_SUBJECT ORDER BY book.BOOK_NUM, book.BOOK_TITLE;

The above query was executed using the tool “Access 2013”.

Explanation:

The above query is used to display the book number, title, subject, average cost of books within that subject and the difference between the cost of each book and the average cost of books in that subject.

  • • From the given query, the “INNER JOIN” operation is used to select all the matching records of “BOOK_SUBJECT” from “averageCalc” and “book”.
    • ○ The “averageCalc” implies select average of book cost and book subject from “BOOK” table...

Still sussing out bartleby?

Check out a sample textbook solution.

See a sample solution

The Solution to Your Study Problems

Bartleby provides explanations to thousands of textbook problems written by our experts, many with advanced degrees!

Get Started

Chapter 8 Solutions

Database Systems: Design, Implementation, & Management
Show all chapter solutions
add
Ch. 8 - Suppose you have two tables: EMPLOYEE and...Ch. 8 - Given the employee information in Question 11,...Ch. 8 - Given the employee information in Question 11,...Ch. 8 - Given the employee information in Question 11,...Ch. 8 - Why does the order of the operands (tables) matter...Ch. 8 - What MS Access and SQL Server function should you...Ch. 8 - What Oracle function should you use to calculate...Ch. 8 - Suppose a PRODUCT table contains two attributes,...Ch. 8 - What string function should you use to list the...Ch. 8 - What is a sequence? Write its syntax.Ch. 8 - What is a trigger, and what is its purpose? Give...Ch. 8 - What is a stored procedure, and why is it...Ch. 8 - What is embedded SQL and how is it used?Ch. 8 - What is dynamic SQL, and how does it differ from...Ch. 8 - Create the tables. (Use the MS Access example...Ch. 8 - Insert the data into the tables you created in...Ch. 8 - Write the query that will generate a combined list...Ch. 8 - Write the query that will generate a combined list...Ch. 8 - Write the query that will show only the duplicate...Ch. 8 - Write the query that will generate only the...Ch. 8 - Write the query to show the invoice number, the...Ch. 8 - Write the query for all the invoices that will...Ch. 8 - Write the query that will write Oracle sequences...Ch. 8 - Modify the CUSTOMER table to include two new...Ch. 8 - Assuming that you completed Problem 10, write the...Ch. 8 - Assuming that the CUSTOMER table contains a...Ch. 8 - Write the query that lists the average age of your...Ch. 8 - Write the trigger to update the CUST_BALANCE in...Ch. 8 - Write a procedure to add a new customer to the...Ch. 8 - Write a procedure to add a new invoice record to...Ch. 8 - Write a trigger to update the customer balance...Ch. 8 - Write a procedure to delete an invoice, giving the...Ch. 8 - Write a query to display the products that have a...Ch. 8 - Write a query to display the current salary for...Ch. 8 - Write a query to display the starting salary for...Ch. 8 - Write a query to display the invoice number, line...Ch. 8 - Write a single SQL command to increase all price...Ch. 8 - Write a query to display the customer code, first...Ch. 8 - LargeCo is planning a new promotion in Alabama...Ch. 8 - One of the purchasing managers is interested in...Ch. 8 - The purchasing manager is still concerned about...Ch. 8 - Create a trigger named trg_line_total to write the...Ch. 8 - Create a trigger named trg_line_prod that...Ch. 8 - Create a stored procedure named prc_inv_amounts to...Ch. 8 - Create a procedure named prc_cus_balance_update...Ch. 8 - Modify the MODEL table to add the attribute and...Ch. 8 - Write the queries to update the MOD_WAIT_CHG...Ch. 8 - Modify the CHARTER table to add the attributes...Ch. 8 - Write the sequence of commands required to update...Ch. 8 - Write the sequence of commands required to update...Ch. 8 - Write the command required to update the...Ch. 8 - Write the command required to update the...Ch. 8 - Write the command required to update the...Ch. 8 - Modify the PILOT table to add the attribute shown...Ch. 8 - Create a trigger named trg_char_hours that...Ch. 8 - Create a trigger named trg_pic_hours that...Ch. 8 - Create a trigger named trg_cust_balance that...Ch. 8 - Write a query to display all rows in the PATRON...Ch. 8 - Write a query to display the patron ID, book...Ch. 8 - Write a query to display the patron ID, patron...Ch. 8 - Write a query to display the book number, title...Ch. 8 - Write a query to display the author last name,...Ch. 8 - Write a query to display the author ID, book...Ch. 8 - Write a query to display the author last name,...Ch. 8 - Write a query to display the patron ID, book...Ch. 8 - Write a query to display the patron ID, full name...Ch. 8 - Write a query to display the book number and the...Ch. 8 - Write a query to display the author ID, first and...Ch. 8 - Write a query to display the book number, title,...Ch. 8 - Write a query to display the book number, title,...Ch. 8 - Write a query to display the book number, title,...Ch. 8 - Write a query to display the author ID, author...Ch. 8 - Write a query to display the patron ID, first and...Ch. 8 - Write a query to display the average number of...Ch. 8 - Write a query to display the patron ID and the...Ch. 8 - Write a query to display the book number, title,...Ch. 8 - Write a query to display the author ID, first and...Ch. 8 - Write a query to display the book number, title,...Ch. 8 - Write a query to display the book number, title,...Ch. 8 - Write a query to display the lowest average cost...Ch. 8 - Alter the DETAILRENTAL table to include a derived...Ch. 8 - Update the DETAILRENTAL table to set the values in...Ch. 8 - Alter the VIDEO table to include an attribute...Ch. 8 - Update the VID_STATUS attribute of the VIDEO table...Ch. 8 - Alter the PRICE table to include an attribute...Ch. 8 - Update the PRICE table to place the values shown...Ch. 8 - Create a sequence named rent_num_seq to start with...

Additional Engineering Textbook Solutions

Find more solutions based on key concepts
Show solutions add
Name the three different types of tooth patterns.

Precision Machining Technology (MindTap Course List)

What are strategic risks?

Cornerstones of Financial Accounting

Calculate the arc length S1 in the accompanying figure. R2 =8 cm, R1 = 5 cm, and S2 = 6.28 cm.

Engineering Fundamentals: An Introduction to Engineering (MindTap Course List)

Convert 10,000 ft-lbf of energy into BTU, Joules, and kilojoules.

Fundamentals of Chemical Engineering Thermodynamics (MindTap Course List)

If your motherboard supports ECC DDR3 memory, can you substitute non-ECC DDR3 memory?

A+ Guide to Hardware (Standalone Book) (MindTap Course List)

inference rules a. processing system in which the computer processes each transaction as it is entered b. appli...

Enhanced Discovering Computers 2017 (Shelly Cashman Series) (MindTap Course List)

After a weld is back gouged and a groove is formed, what should be done?

Welding: Principles and Applications (MindTap Course List)