DB Managment Ch7 Problems
DB Managment Ch7 Problems
10. Write a query to count the number of customers with a balance of more than
$500.
11. Generate a listing of all purchases made by the customers, using the output
shown in Figure P7.11 as your guide. Sort the results by customer code, invoice
number, and product description.
12. Using the output shown in Figure P7.12 as your guide, generate a list of
customer purchases, including the subtotals for each of the invoice line numbers.
The subtotal is a derived attribute calculated by multiplying LINE_UNITS by
LINE_PRICE. Sort the output by customer code, invoice number, and product
description. Be certain to use the column aliases as shown in the figure.
13. Write a query to display the customer code, balance, and total purchases for
each customer. Total purchase is calculated by summing the line subtotals (as
calculated in Problem 12) for each customer. Sort the results by customer code, and
use aliases as shown in Figure P7.13
14. Modify the query in Problem 13 to include the number of individual product
purchases made by each customer. (In other words, if the customer’s invoice is
based on three products, one per LINE_NUMBER, you count three product
purchases. Note that in the original invoice data, customer 10011 generated three
invoices, which contained a total of six lines, each representing a product purchase.)
Your output values must match those shown in Figure P7.14, sorted by customer
code.
15. Use a query to compute the total of all purchases, the number of purchases, and
the average purchase amount made by each customer. Your output values must
match those shown in Figure P7.15. Sort the results by customer code.
Database Management Ch7 Problems Garcia3
16. Create a query to produce the total purchase per invoice, generating the results
shown in Figure P7.16, sorted by invoice number. The invoice total is the sum of the
product purchases in the LINE that corresponds to the INVOICE.
17. Use a query to show the invoices and invoice totals in Figure P7.17. Sort the
results by customer code and then by invoice number.
18. Write a query to produce the number of invoices and the total purchase amounts
by customer, using the output shown in Figure P7.18 as your guide. Note the results
are sorted by customer code. (Compare this summary to the results shown in
Problem 17.)
Database Management Ch7 Problems Garcia4
19. Write a query to generate the total number of invoices, the invoice total for all of
the invoices, the smallest of the customer purchase amounts, the largest of the
customer purchase amounts, and the average of all the customer purchase amounts.
Your output must match Figure P7.19.
20. List the balances of customers who have made purchases during the current
invoice cycle—that is, for the customers who appear in the INVOICE table. The
results of this query are shown in Figure P7.20, sorted by customer code.
21. Provide a summary of customer balance characteristics for customers who made
purchases. Include the minimum balance, maximum balance, and average balance,
as shown in Figure P7.21
AVG(BALANCE) AS AVG_BALANCE
FROM CUSTOMER
WHERE CUST_CODE IN (
SELECT DISTINCT CUST_CODE
FROM INVOICE
);
22. Create a query to find the balance characteristics for all customers, including the
total of the outstanding balances. The results of this query are shown in Figure 7.22.
23. Find the listing of customers who did not make purchases during the invoicing
period. Sort the results by customer code. Your output must match the output
shown in Figure P7.23.
SELECT CUSTOMER.*
FROM CUSTOMER
LEFT JOIN INVOICE ON CUSTOMER.CUST_CODE = INVOICE.CUST_CODE
WHERE INVOICE.INVOICE_DATE IS NULL
ORDER BY CUSTOMER.CUST_CODE;
24. Find the customer balance summary for all customers who have not made
purchases during the current invoicing period. The results are shown in Figure
P7.24.
25. Create a query that summarizes the value of products currently in inventory.
Note that the value of each product is a result of multiplying the units currently in
inventory by the unit price. Sort the results in descending order by subtotal, as
shown in Figure P7.25.
26. Find the total value of the product inventory. The results are shown in Figure
P7.26.