For each customer state, output the state abbreviation (CustState) and the average household income for all customers in that state.

computer science

Description

 

Part B Answers (9 Points Each)

1. For each customer state, output the state abbreviation (CustState) and the average household income for all customers in that state. Order results alphabetically by state abbreviation and be sure that the average household income column includes a meaningful column name. (Hint: You only need to use one table for this query since you are not asked to give the actual name of the state.) (Remember: only copy the top 10 rows – do not worry about the Headers or Copy with Headers).

SQL Query Syntax Output of the Query*



2. Output the customer name (Fname and Lname), marital status, state (use the actual state name), and household income for all customers located in Colorado (CO), Utah (UT), Washington (WA), and Wyoming (WY) who have a household income of under $119,500 and are married. Order results alphabetically by last name. Your query should not include the OR operator. (Remember: only copy the top 10 rows – do not worry about the Headers or Copy with Headers).

SQL Query Syntax Output of the Query*



3. For all orders placed on August 9, 2019 and valued at $1,125 or less, show the customer’s name (first and last), the order number, and the order total. Results should be put in order from the largest value to the smallest. (Remember: only copy the top 10 rows – do not worry about the Headers or Copy with Headers).

SQL Query Syntax Output of the Query*



4. For each state, what percentage of the state’s population purchased a DustBunny vacuum (assume everyone in the customer table has purchased a DustBunny vacuum)? Your output should include the state name, population, number of purchasers from that state, and the percentage (show as a decimal). Order the output from the highest percentage to the lowest and make sure each column has a usefully descriptive name. (Remember: only copy the top 10 rows – do not worry about the Headers or Copy with Headers).

SQL Query Syntax Output of the Query*



5. Show the five orders that included the highest number of items (e.g., if an order included 2 of one type of vacuum and 1 of another, that equates to three items). For each order, show the customer first name, customer last name, number of items, the order date, and the total value of the order. Order results from highest number of items to lowest.

SQL Query Syntax Output of the Query*



6. Which states’ customers have an average household income over $120,000? Output the name of each state that meets this requirement, the name of the region where the state is located, and the states’ customers’ average household income (HHI); order the output in descending order from highest HHI to lowest and be sure each column has a meaningful name.

SQL Query Syntax Output of the Query*



7. How many units of each vacuum model were sold during the period from August 11-20, 2019, and what was the total revenue generated by those sales? Order results from the product with the highest revenue to the lowest, include the ModelName in your output, and be sure that all columns have meaningful names. Your output should only include vacuum models (not warranties). 

SQL Query Syntax Output of the Query*



8. What is the most popular product for customers who own pets? Answer the question by outputting the name of the most popular product and the number of units sold to pet owners as well as the total amount of revenue generated from the sale of those units to pet owners. Be sure your columns have meaningful names and that your query only outputs the one most popular product.

SQL Query Syntax Output of the Query*



*If the query returns more than 10 lines, include only the first 10 lines of output.


Part C Answers (5 Points Each)

1. Assume you wanted to add another state to the database, the state of Nevernia. Nevernia has a state code of NA, is in region 2, and has a population of 40,000. Nevernia is a small state. Include in your submission (1) the query that you would use to add this additional record to the database and (2) the output of a query that shows the StateIDS, RegionID, Population, and StateName of all states with a population under 1,000,000 AS WELL AS the query you used to generate this output.

INSERT INTO Query Syntax (1)



SELECT Query Syntax (2) Output of the Query*

2. Vivian Dunn (CustID 936) was recently married. Vivian has formally requested a name change and also a marital status change. Change the Customer table in your personal database so that Vivian Dunn’s last name is now Bryant and her marital status is changed from ‘single’ to ‘married.’ Run the following query to verify Vivian’s Customer ID and to get acquainted with all the customers in the Customer table with the Lname “Dunn” or “Bryant” (note: only one last name—Vivian’s—of the 6 records should change when you run your UPDATE query):

SELECT *

FROM Customer

WHERE Lname = 'Dunn' OR Lname = 'Bryant';

Include in your submission (1) the query that you would use to change (update) Vivian’s record in the database and (2) the output of a query that shows Vivian’s updated record AS WELL AS the query you used to generate this output.

UPDATE Query Syntax (1)



SELECT Query Syntax (2) Output of the Query*


Instruction Files

Related Questions in computer science category