Complete the following SQL queries on the Premier Products

advertisement
Complete the following SQL queries on the Premier Products database.
Single-Table Queries
Use SQL to do the following:
1. Find the part number and description of all parts.
2. List the complete SLSREP table.
3. Find the names of all the customers who have a credit limit of at least $800.
4. Give the order numbers of those orders placed by customer 124 on 05/09/91.
5. List the numbers and names of those customers represented by sales rep 3 or sales rep 12.
6. List the part number and description of all parts that are not in item class HW.
7. List the part number and description of all parts that have between 100 and 200 units on hand.
Do this in two ways.
8. Give the part number, description, and on-hand value (units on hand * price) for each part in
item class AP. (On-hand value is really units on hand * cost but we do not have a cost
column in the PART table.)
9. Give the part number, description, and on-hand value for each part whose on-hand value is at
least 1,000.
10. List the part number and description of all parts whose item class is HW or SG. Use the word
IN in your formulation.
11. Find the number and name of all customers whose last name is Nelson.
12. List al details about parts. Sort the output by part description.
13. List all details about parts. Sort the output by part number within item class.
14. Find out how many customers have a balance that exceeds their credit limit.
15. Find the total of the balances for all customers represented by sales rep 12.
16. List the number, description, and units on hand of all parts whose number of units on hand is
more than average.
17. List the totals of the balances for the customers of each sales rep. In a second query, list only
the totals of the balances for sales reps with at least four customers.
Multiple-Table Queries
Use SQL to do the following:
1. For each order, list the order number and date along with the number and name of the
customer who placed the order.
2. For each order placed on September 5, 1991, list the order number and date along with the
number and name of the customer who placed the order.
3. For each order, list the order number and the order date as well as the part number, number of
units ordered, and quoted price for each of the order lines that make up the order.
4. Find the numbers and names of all customers who placed orders on September 5, 1991. Do
this in two ways. First, use the word IN; second, use the word EXISTS.
5. Find the numbers and names of all customers who did not place an order on September 5,
1991.
6. For each order, list the order number and the order date as well as the part number, part
description, and item class of all parts that make up the order.
7. Find the numbers and names of all sales reps who represent at least one customer with a credit
limit of $1000. Do this in two ways. In one solution use a subquery; in the other, do not use
a subquery.
8. Find the numbers and names of those customers who currently have an order on file for an
IRON.
9. List the numbers, descriptions, and item class of any pairs of parts that are in the same item
class and warehouse.
10. List the order number and date of all orders placed by Mary Nelson that contain an order line
for weights.
11. List the order number and date of all orders placed by Mary Nelson that do not contain an
order line for weights.
12. List the order number and date of all orders that were either placed by Mary Nelson or that
contain an order line for an iron.
13. List the part number and part description for all parts that have a unit price greater than the
unit price of any parts in item class HW. Use either the word ALL or the word ANY in your
command. (Hint: Be careful about which one you use.)
14. If you used ALL in Exercise 13, change it to ANY. If you used ANY, change it to all. Once
you have done this, run the new command. What question is this command answering?
Download