Week 12

Post date: Dec 11, 2016 7:15:54 AM

customers

items_ordered

Using the above tables, answer the following questions:

    1. Select the maximum price of any item ordered in the items_ordered table. Hint: Select the maximum price only.

    2. Select the average price of all of the items ordered that were purchased in the month of Dec.

    3. What are the total number of rows in the items_ordered table?

    4. For all of the tents that were ordered in the items_ordered table, what is the price of the lowest tent? Hint: Your query should return the price only.

Solution

    1. How many people are in each unique state in the customers table? Select the state and display the number of people in each. Hint: count is used to count rows in a column, sum works on numeric data only.

    2. From the items_ordered table, select the item, maximum price, and minimum price for each specific item in the table. Hint: The items will need to be broken up into separate groups.

    3. How many orders did each customer make? Use the items_ordered table. Select the customerid, number of orders they made, and the sum of their orders. Click the Group By answers link below if you have any problems.

Solution

    1. How many people are in each unique state in the customers table that have more than one person in the state? Select the state and display the number of how many people are in each if it's greater than 1.

    2. From the items_ordered table, select the item, maximum price, and minimum price for each specific item in the table. Only display the results if the maximum price for one of the items is greater than 190.00.

    3. How many orders did each customer make? Use the items_ordered table. Select the customerid, number of orders they made, and the sum of their orders if they purchased more than 1 item.

Solution

    1. Select the lastname, firstname, and city for all customers in the customers table. Display the results in Ascending Order based on the lastname.

    2. Same thing as exercise #1, but display the results in Descending order.

    3. Select the item and price for all of the items in the items_ordered table that the price is greater than 10.00. Display the results in Ascending order based on the price.

Solution

    1. Select the customerid, order_date, and item from the items_ordered table for all items unless they are 'Snow Shoes' or if they are 'Ear Muffs'. Display the rows as long as they are not either of these two items.

    2. Select the item and price of all items that start with the letters 'S', 'P', or 'F'.

Solution