MySQLworkbench homework help
BA 497/597 – SQL Homework 3 – Summarizing Data
Copy this document to your local drive and add your name to the footer
Create SQL commands to answer the following questions using the tables shown below from the classicmodels database. Paste your SQL code below each question along with a screen shot of the first few rows of the results grid.
Submit the completed document in Moodle.
For all problems, use a single word alias (no quote marks) for any calculated fields. Limit long output to the first 5 rows.
Example: SELECT AVG(amount) AS Avg_Payment
The following questions use aggregate functions and all will require a GROUP BY clause. Some of them will require a HAVING clause if you are making selection criteria based on results from aggregated functions.
1. Show the count of orders by status in the orders table. Use the alias N_Status for the counts.
1. Show the count of orders by customer number in the orders table. Use the alias N_Status for the counts. Order by counts from highest to lowest.
1. Write a query to show the customer number, the count of checks, and the total payments made by customer. Use the aliases N_Checks and Total_Paid. Order by the total paid.
1. Show the minimum, maximum, and average credit limit by city. Use the aliases Min_Limit, Max_Limit, and Average_Limit. Sort by city in alphabetical order.
1. Show the number of customers and average credit limit for customers in zip code (postalCode) 94217. Use appropriate aliases and round the average credit limit to 0 decimal places. (HINT: use a WHERE clause for the zip code.)
1. Show the number of payments received each month in 2003.
1. Show the months in 2003 that had more than 10 payments. (HINT: You need a HAVING clause.)
1. Show the average credit limit by city for all cities that have an average limit between $99,000 and $150,000. Use the alias Average_Limit for the averages. Sort by the average credit limits, largest to smallest. (HINT: You need a HAVING clause.)
1. Show the count of customers by state for all states that have more than 2 customers. Use the alias N_State for the counts. Sort by state in alphabetical order. Make sure you do not count customers that have Null values in the state field. (HINT: You need a HAVING clause.)
Your Name Goes Here SQL Homework 3 Page 2 of 2