Sunteți pe pagina 1din 3

Please create following tables by using MySQL and answer the following questions.

Submit a table creation script and data insert script. Then prepare the report as follows:
question number, question, SQL statement and the result table for each question.
J
j_num

jname

j1
j2
j3
j4
j5
j6
j7

city

Sorter
Punch
Reader
Console
Collator
Terminal
Tape

Paris
Rome
Athens
Athens
London
Oslo
London

P
p_num
p1
p2
p3
p4
p5
p6

pname
Nut
Bolt
Screw
Screw
Cam
Cog

color
Red
Green
Blue
Red
Blue
Red

weight

city
12
17
17
14
12
19

London
Paris
Rome
London
Paris
London

S
s_num
s1
s2
s3
s4
s5

s_name

status

Smith
Jones
Blake
Clark
Adams

city
20
10
30
20
30

London
Paris
Paris
London
Athens

SPJ
s_num
s1
s1
s2
s2
s2
s2
s2
s2
s2
s2
s3
s3
s4

p_num
p1
p1
p3
p3
p3
p3
p3
p3
p3
p5
p3
p4
p6

j_num
j1
j4
j1
j2
j3
j4
j5
j6
j7
j2
j1
j2
j3

qty
200
700
400
200
200
500
600
400
800
100
200
500
300

s4
s5
s5
s5
s5
s5
s5
s5
s5
s5
s5

p6
p1
p2
p2
p3
p4
p5
p5
p5
p6
p6

j7
j4
j2
j4
j4
j4
j4
j5
j7
j2
j4

300
100
200
100
200
800
400
500
100
200
500

Note: Qty, status, and weight are numbers.


Exercise
1. Get supplier names and numbers for all suppliers who supplied part P3 and whose
name begins with letter A.
2. Get supplier names and numbers for all suppliers whose name (supplier name) begins
with letter A and who supplied parts whose name (parts name) begins with setter S.
3. Get supplier names for suppliers who supplied for job J2. (Use a sub query)
4. Get supplier names for suppliers who supplied parts for jobs only in Athens. (Use sub
query)
5. Get part names for parts that are not supplied for job J3. (Use a sub query)
6. Get supplier numbers for suppliers with status lower than that of supplier S1.
7. Get supplier numbers and names for suppliers whose status is greater than status values
of all suppliers in located Paris.
8. Calculate each suppliers total sales quantity and get the sales persons name if the
sales person supplies parts more than 1000 units in total.
9. Get job numbers for jobs whose city is first in the alphabetical list of the job cities.
10. Increase the status values of suppliers by 5 who are located in Paris.
Please hand in the modified table and the query.
11. Change the name to Hammer of parts that are Red and located in London and whose
name was Screw.
Please hand in the modified table and the query.
12. Delete all jobs in Rome and all corresponding part shipments. (Please use 2 queries)

Please hand in the modified table and the query.


13. Smith moved to Adams location. Please update Smiths city but do not use the city
name directly.
14. Please create a view table supplier_shipment that shows each supplier and its total
shipment quantity. (if the system do not allow you to create a view table then skip this
question)
15. Please try to increase Smiths total shipment by 100 in the view table you created in
question 14. Then discuss what happens when you try to update the view table. (if
question 14 is successful)
16. Please create a base table supplier_shipment that shows each supplier and its total
shipments from S and SPJ tables.
17. Please repeat question 15 on the base table supplier_shipment and discuss the result.

S-ar putea să vă placă și