SQL Assignment

Due: September 18, 2009

Download this file, unzip and execute the three file within the MySql command window. This will change three of your tables in the database. You should have 1337 rows in stockorders, 756 rows in stockprices, 3 rows in stocks and 457 rows in customers after the changes.

Using the MySQL SQL interface, answer the following queries. Put your name in the file within a comment. For each query, include a comment that states how you are solving the query. All columns must have reasonable names.

  1. Find the name of all customers who have purchased stock with the symbol "DELL"
  2. Find the name of all customers who have purchased stock with the symbol "MSFT" and stock with the symbol "APPL"
  3. Find the total amount spent on stock purchases by each customer.
  4. Find the name of the company with the highest average closing price
  5. For each state, find the number of customers with more than 5 transactions.
  6. For each state, find the number of shares of "APPL" owned by customers living in that state
  7. Find all days in which the closing price of APPL is higher than the closing price of MSFT
  8. Find all transaction pairs in which the same customer sold the same stock (and same number of shares) for less than they purchased it. Output the customers name, the day of each transaction, and the prices.
  9. Find all days in which no stock for any company was bought or sold.
  10. Find all customers who have at least one transaction for every stock