Question

Write a query to produce the number of invoices and the total purchase amounts by customer

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

image.png

3 2
Add a comment Improve this question Transcribed image text
Answer #1

Query Solution:

SELECT CUS_CODE,

COUNT(INV_NUMBER) AS 'Number of Invoices',

AVG(INV_TOT) AS 'Average Invoice Amount',

MAX(INV_TOT) AS 'Max Invoice Amount',

MIN(INV_TOT) AS 'Min Invoice Amount',

SUM(INV_TOT) AS 'Total Customer Purchases'

FROM (SELECT CUS_CODE, L.INV_NUMBER AS INV_NUMBER,

SUM(L.LINE_UNITS*L.LINE_PRICE) AS INV_TOT

FROM INVOICE I, LINE L

WHERE I.INV_NUMBER = L.INV_NUMBER

GROUP BY CUS_CODE, L.INV_NUMBER) AS IL

GROUP BY CUS_CODE ;

Add a comment
Know the answer?
Add Answer to:
Write a query to produce the number of invoices and the total purchase amounts by customer
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • The Ch07_ConstructCo database stores data for a consultingcompany that tracks all charges to projects. The...

    The Ch07_ConstructCo database stores data for a consulting company that tracks all charges to projects. The charges are based on the hours each employee works on each project. The structure and contents of the Ch07_ConstructCo database are shown in Figure P7.1.Note that the ASSIGNMENT table in Figure P7.1 stores the JOB_CHG_HOUR values as an attribute (ASSIGN_CHG_HR) to maintain historical accuracy of the data. The JOB_CHG_HOUR values are likely to change over time. In fact, a JOB_CHG_ HOUR change will be...

  • Create sql query command for the following. Modify your query and produce the following results. Customer...

    Create sql query command for the following. Modify your query and produce the following results. Customer #000000001 1 1428873.61 9 Customer #000000002 2 1156504.92 10 Customer #000000004 4 4134567.39 31 Customer#000000005 5 1084042.74 9 Customer #000000007 7 3922020.98 24 Column 1 is the customer Name, Column 2, is the customer key, column 3 is the total of the customer orders ($$) and column 4 is the number of orders.

  • Problem 33, chapter 7 from Database Systems 13th edition by Coronel Write a query to display...

    Problem 33, chapter 7 from Database Systems 13th edition by Coronel Write a query to display the employee number, last name, email address, title, and department name of each employee whose job title ends in the word “ASSOCIATE.” Sort the output by department name and employee title Problem 36, chapter 7 from Database Systems 13th edition by Coronel Write a query to display the number of products within each base and type combination, sorted by base and then by type...

  • 14. Write a query that lists the trip id, trip name and state for all trips...

    14. Write a query that lists the trip id, trip name and state for all trips in New Hampshire. Run "Explain" against this query. Now create an index on the state. Re-run your query and the "Explain" Are there differences in the Explain results? Why or why not? Customer Customer Num LastName FirstName Address City State PostalCode Phone Reservation ReservationID TripID Trip Date Num Persons Trip Price Other Fees Customer Num Trip Guide TripID Guide Num LastName Trip Name Start...

  • 2. SQL queries (40 points total, 5 points each query) Write SQL query statements to query...

    2. SQL queries (40 points total, 5 points each query) Write SQL query statements to query the following Hotel Room Booking Database Tables. "cid" is Customer ID. "rid" is Room ID. "bid" is Booking ID. "dob" means Date of Vwwww Birth; "beds" means the number of beds in the room which is normally 1 or 2 beds. "DueDate" and "DueAmount" are the payment due dates and due amounts of this booking. Customers fname name phone email cid dob zipcode Rooms...

  • SQL Homework 1. For each reservation, list the reservation ID, trip ID, customer number, and customer...

    SQL Homework 1. For each reservation, list the reservation ID, trip ID, customer number, and customer last name. Order the results by customer last name. 2. For each reservation for customer Ryan Goff, list the reservation ID, trip ID, and number of persons. 3. List the trip name of each trip that has Miles Abrams as a guide. 4. List the trip name of each trip that has the type Biking and that has Rita Boyers as a guide. 5....

  • What is a python code that print a session summary that includes total number of carts,...

    What is a python code that print a session summary that includes total number of carts, total number of items, and total cost. And Output for the cart contents and session summary must use the print ‘format’ option to ensure the output is lined up, uses 2 digits to the right of the decimal for dollar amounts, and shows all columns as being lined up straight. Example: <start of output> Total number of carts: 5 Total number of items: 9...

  • Write a program that will compute the total sales tax on a $95 purchase. Assume the...

    Write a program that will compute the total sales tax on a $95 purchase. Assume the state sales tax is 4 percent and the county sales tax is 2 percent ... and then display the amounts for the total sales tax, state sales tax, and county sales tax. the pseudo code is: since the tax rates do not vary, we will declare them as constants: const double STATE_SALES_TAX_RATE = 0.04 //copy initialization const double CNTY_SALES_TAX_RATE(0.02) //direct initialization declare variable to...

  • please write a c++ file using these two invoices attached as well as 2 extra for...

    please write a c++ file using these two invoices attached as well as 2 extra for the output. please do not use any libraiers other then, #include <fstream> #include <iostream> #include <string> #include<iomanip> (for styling.) Do not use void either. The program should ask for LastName FirstName DaysofRental and BalanceDue and sort it by last name then save to a file. Preconditions: File always has 10 records. The specification is as follows: ⦁ Sort the input file by last name,...

  • Can you please write the MySQL Query sentences for the following items below? For example: SELECT...

    Can you please write the MySQL Query sentences for the following items below? For example: SELECT * FROM employees; Generate a list of salespeople sorted descending by hire date. Show the ID, first name, last name, hire date, and salary for each salesperson. Generate a list of customers whose last name begins with the letter “M.” Show the first and last names of these customers. Sort the list of customers descending by last name. C. Generate a list of customers...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT