SQL-Take Home Test—100 Points

advertisement
SQL-Take Home Test—100 Points
Instructions: You are to create a database and enter the following information into MS Access.
Additionally, you will be required to create scripts of your database for create, populate, and drop. You are
to design the database to the specifications provided given the tables provided below. You are also asked
to answer the sql questions provided within the test.
Tables:
Name: Salesperson1
Sal_ID Sal_LName
1124
Abel
1547
Baker
1254
Jones
3259
Murphy
1457
Zenith
5248
Kabad
Sal_Age
63
38
26
42
59
27
Sal_Sal
120000
42000
36000
50000
47000
63000
Sal_CommRate
.07
.06
.03
.04
.08
.09
Name: Customer1
Cus_ID
Cus_Name
966854
Abernathy
542154
Manchester
524157
Tri-City
635215
Borint
448795
Corrigan
Cus_City
Willowton
Aelxandria
Memphis
Willowton
Memphis
Cus_IndType
B
D
F
D
G
Name: Orders1
Ord_ID
12-585
13-854
16-857
21-836
27-854
11-522
16-625
Cus_ID
524157
635215
448795
542154
966854
542154
966854
Sal_ID
1254
1457
1254
1124
3259
1124
1124
Part_Cost
G4
12.52
8.52
14.58
63.52
22.25
33.63
Part_Location
Ord_Date
09-12-99
10-11-98
11-13-98
07-25-94
06-18-94
09-22-96
11-12-99
Name: Order_Line1
Ord_ID
Part_ID
16-625
411
12-585
522
27-854
411
16-625
522
13-854
365
16-857
112
16-857
365
16-625
112
13-854
633
Name: Part1
Part_ID
112
365
632
411
522
966
633
Part_Desc
Baseball 5.52
Boxing Gloves
Slide Pants
Football
Racquet
Helmet
Judo Suit
H7
B8
P9
P5
G8
K7
SQL Questions:
Single Table Queries
1.
2.
3.
4.
5.
6.
Display the salespeople’s last names that have salaries above the average salary.
Display the part id’s that begin with 6.
Display all the attributes from the orders placed in month 11.
Display the salesperson’s id that is associated with the minimum age.
Display the part descriptions that are from a part location that has a 7 in it.
Display the salesperson’s last name that is the oldest.
Multi-Table Join Queries—You are to perform the following queries using the multi-table joins
1.
2.
3.
4.
5.
6.
7.
Display distinct salesperson’s last name associated with orders placed in month 09 or 11.
Display distinct customer’s names that have a current order for a product that costs over 9 dollars.
Display distinct salesperson’s id, and last name that have sold any products that cost over 12 dollars
and have a part location beginning with G or P.
Display the customer name and city that have a product on order that has a cost greater than the
average.
Display the customer id that is from a city beginning with W, and has a Racquet on order.
Display order id, part id, and retail price of the part (defined as part_cost * 1.45) for each order.
Display the order id, and the sum (retail price) as defined in the previous problem grouped by order id,
order by order id in descending order.
Multi-Table Sub Queries—You are to perform the following queries using Sub Queries—NO JOINS!
*Please note, the first five of the six queries required below are taken from the section above.
1.
2.
3.
4.
5.
6.
Display distinct salesperson’s last name associated with orders placed in month 09 or 11.
Display distinct customer’s names that have a current order for a product that costs over 9 dollars.
Display distinct salesperson’s id, and last name that have sold any products that cost over 12 dollars
and have a part location beginning with G or P.
Display the customer name and city that have a product on order that has a cost greater than the
average.
Display the customer id that is from a city beginning with W, and has a Racquet on order.
Display the average salesperson age and average salesperson salary for all salespeople associated with
a customer.
Additional requirements for those doing this on the MS Access platform for the extra credit
1.
2.
3.
4.
5.
6.
7.
Insert a new row in customer with the following values: 524879, Hardon, Benton, H.
Change the age for the salesperson 1254 to: 33.
Create a new table from salesperson1 for sales peopole that make over 50,000. Include all columns in
the new table call the table EliteSales. (**Hint, this will take two SQL commands to complete.)
Delete the part_id 633 record from the part table.
Change the salary for Jones to 76,000.
Increase the price charged for all part by an additional 10% in the parts table.
Change sales person Abel’s name to Mandon.
Download