SlideShare a Scribd company logo
1 of 10
Download to read offline
J
j_num
jname
city
j1
Sorter
Paris
j2
Punch
Rome
j3
Reader
Athens
j4
Console
Athens
j5
Collator
London
j6
Terminal
Oslo
j7
Tape
London
P
p_num
pname
color
weight
city
p1
Nut
Red
12
London
p2
Bolt
Green
17
Paris
p3
Screw
Blue
17
Rome
p4
Screw
Red
14
London
p5
Cam
Blue
12
Paris
p6
Cog
Red
19
London
S
s_num
s_name
status
city
s1
Smith
20
London
s2
Jones
10
Paris
s3
Blake
30
Paris
s4
Clark
20
London
s5
Adams
30
Athens
SPJ
s_num
p_num
j_num
qty
s1
p1
j1
200
s1
p1
j4
700
s2
p3
j1
400
s2
p3
j2
200
s2
p3
j3
200
s2
p3
j4
500
s2
p3
j5
600
s2
p3
j6
400
s2
p3
j7
800
s2
p5
j2
100
s3
p3
j1
200
s3
p4
j2
500
s4
p6
j3
300
s4
p6
j7
300
s5
p1
j4
100
s5
p2
j2
200
s5
p2
j4
100
s5
p3
j4
200
s5
p4
j4
800
s5
p5
j4
400
s5
p5
j5
500
s5
p5
j7
100
s5
p6
j2
200
s5
p6
j4
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 (part’s 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 supplier’s total sales quantity and get the sales person’s 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 Adam’s location. Please update Smith’s 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 Smith’s 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.
Note: You might need following setting before run your update SQL
SET SQL_SAFE_UPDATES = 0;
j_num
jname
city
j1
Sorter
Paris
j2
Punch
Rome
j3
Reader
Athens
j4
Console
Athens
j5
Collator
London
j6
Terminal
Oslo
j7
Tape
London
Solution
If you have any doubts, please give me comment...
-- 1. Get supplier names and numbers for all suppliers who supplied part P3 and whose name
begins with letter A.
SELECT s_name, s_num
FROM S INNER JOIN SPJ ON S.s_num = SPJ.s_num
WHERE s_name LIKE 'A%' AND p_num = P3;
-- 2. Get supplier names and numbers for all suppliers whose name (supplier name) begins with
letter A and who supplied parts whose name (part’s name) begins with setter S.
SELECT s_name, s_num
FROM (S INNER JOIN SPJ ON S.s_num = SPJ.s_num) INNER JOIN P ON SPJ.p_num =
P.p_num
WHERE s_name LIKE 'A%' AND pname = 'S%';
-- 3. Get supplier names for suppliers who supplied for job J2. (Use a sub query)
SELECT s_num
FROM S
WHERE s_num IN(
SELECT s_num
FROM SPJ
WHERE j_num = 'j2'
);
-- 4. Get supplier names for suppliers who supplied parts for jobs only in Athens. (Use sub
query)
SELECT s_num
FROM (S INNER JOIN SPJ ON S.s_num = SPJ.s_num) INNER JOIN J ON SPJ.j_num =
J.j_num
WHERE J.city = 'Athens' AND s_num NOT IN(
SELECT s_num
FROM (S INNER JOIN SPJ ON S.s_num = SPJ.s_num) INNER JOIN J ON SPJ.j_num =
J.j_num
WHERE J.city <> 'Athens'
);
-- 5. Get part names for parts that are not supplied for job J3. (Use a sub query)
SELECT pname
FROM P
WHERE p_num NOT IN(
SELECT p_num
FROM SPJ
WHERE p_num = 'j3'
);
-- 6. Get supplier numbers for suppliers with status lower than that of supplier S1.
SELECT s_num
FROM S
WHERE status < (
SELECT status
FROM S
WHERE s_num = 's1'
);
-- 7. Get supplier numbers and names for suppliers whose status is greater than status values of
all suppliers in located Paris.
SELECT s_num, sname
FROM S
WHERE status > ALL(
SELECT status
FROM S
WHERE city = Paris
);
-- 8. Calculate each supplier’s total sales quantity and get the sales person’s name if the sales
person supplies parts more than 1000 units in total.
SELECT S.s_num, s_name, SUM(qty)
FROM S INNER JOIN SPJ ON S.s_num = SPJ.s_num
GROUP BY S.s_num,s_name
HAVING SUM(qty)>1000;
-- 9. Get job numbers for jobs whose city is first in the alphabetical list of the job cities.
SELECT j_num
FROM J
WHERE j_num IN(
SELECT j_num
FROM J
ORDER BY city
LIMIT 1
);
-- 10. Increase the status values of suppliers by 5 who are located in Paris.
-- Please hand in the modified table and the query.
UPDATE S SET status = status+5 WHERE city ='Paris';
SELECT *
FROM S;
-- 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.
UPDATE P SET pname = 'Hammer' WHERE color = 'Red' AND city ='London' AND
pname='Screw';
SELECT *
FROM P;
-- 12. Delete all jobs in Rome and all corresponding part shipments. (Please use 2 queries)
-- Please hand in the modified table and the query.
DELETE FROM SPJ WHERE j_num IN (
SELECT j_num
FROM J
WHERE city = 'Rome'
);
DELETE FROM J WHERE city ='Rome';
-- 13. Smith moved to Adam’s location. Please update Smith’s city but do not use the city name
directly.
UPDATE S SET city = (SELECT city FROM S WHERE s_name='Adams') WHERE
s_name='Smith';
-- 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)
CREATE VIEW supplier_shipment AS
SELECT s_num, SUM(qty) AS qty
FROM SPJ
GROUP s_num;
-- 15. Please try to increase Smith’s 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)
UPDATE supplier_shipment SET qty = qty +100;
-- 16. Please create a base table supplier_shipment that shows each supplier and its total
shipments from S and SPJ tables.
DESCRIBE supplier_shipment;

More Related Content

More from fatoryoutlets

Suppose the rate of plant growth on Isle Royale supported an equilib.pdf
Suppose the rate of plant growth on Isle Royale supported an equilib.pdfSuppose the rate of plant growth on Isle Royale supported an equilib.pdf
Suppose the rate of plant growth on Isle Royale supported an equilib.pdf
fatoryoutlets
 
Note Use Java Write a web server that is capable of processing only.pdf
Note Use Java Write a web server that is capable of processing only.pdfNote Use Java Write a web server that is capable of processing only.pdf
Note Use Java Write a web server that is capable of processing only.pdf
fatoryoutlets
 
Negotiations are not usually faster in Deal focused cultures than re.pdf
Negotiations are not usually faster in Deal focused cultures than re.pdfNegotiations are not usually faster in Deal focused cultures than re.pdf
Negotiations are not usually faster in Deal focused cultures than re.pdf
fatoryoutlets
 
9. The tort of assault and the tort of battery A) can occur independe.pdf
9. The tort of assault and the tort of battery A) can occur independe.pdf9. The tort of assault and the tort of battery A) can occur independe.pdf
9. The tort of assault and the tort of battery A) can occur independe.pdf
fatoryoutlets
 
If law enforcement fails to give the defendant their Miranda rights,.pdf
If law enforcement fails to give the defendant their Miranda rights,.pdfIf law enforcement fails to give the defendant their Miranda rights,.pdf
If law enforcement fails to give the defendant their Miranda rights,.pdf
fatoryoutlets
 
Identify one cyberattack that occurred in the last 2 years. What cau.pdf
Identify one cyberattack that occurred in the last 2 years. What cau.pdfIdentify one cyberattack that occurred in the last 2 years. What cau.pdf
Identify one cyberattack that occurred in the last 2 years. What cau.pdf
fatoryoutlets
 
How you will respond empathetically, ethically, and legally to famil.pdf
How you will respond empathetically, ethically, and legally to famil.pdfHow you will respond empathetically, ethically, and legally to famil.pdf
How you will respond empathetically, ethically, and legally to famil.pdf
fatoryoutlets
 
How can an insoluble salt with a basic anion be made to dissolve.pdf
How can an insoluble salt with a basic anion be made to dissolve.pdfHow can an insoluble salt with a basic anion be made to dissolve.pdf
How can an insoluble salt with a basic anion be made to dissolve.pdf
fatoryoutlets
 
HELP IN JAVACreate a main method and use these input files to tes.pdf
HELP IN JAVACreate a main method and use these input files to tes.pdfHELP IN JAVACreate a main method and use these input files to tes.pdf
HELP IN JAVACreate a main method and use these input files to tes.pdf
fatoryoutlets
 
Describe the steps in Sanger DNA sequencing. Provide a high level des.pdf
Describe the steps in Sanger DNA sequencing. Provide a high level des.pdfDescribe the steps in Sanger DNA sequencing. Provide a high level des.pdf
Describe the steps in Sanger DNA sequencing. Provide a high level des.pdf
fatoryoutlets
 
d. Which of the following accounts should be reviewed by the auditor.pdf
d. Which of the following accounts should be reviewed by the auditor.pdfd. Which of the following accounts should be reviewed by the auditor.pdf
d. Which of the following accounts should be reviewed by the auditor.pdf
fatoryoutlets
 

More from fatoryoutlets (20)

the ability of the cardiac muscle cells to fire on their own is .pdf
the ability of the cardiac muscle cells to fire on their own is .pdfthe ability of the cardiac muscle cells to fire on their own is .pdf
the ability of the cardiac muscle cells to fire on their own is .pdf
 
Template LinkedList;I am using templates to make some linkedLists.pdf
Template LinkedList;I am using templates to make some linkedLists.pdfTemplate LinkedList;I am using templates to make some linkedLists.pdf
Template LinkedList;I am using templates to make some linkedLists.pdf
 
Surface water entering the North Atlantic may have a temperature of .pdf
Surface water entering the North Atlantic may have a temperature of .pdfSurface water entering the North Atlantic may have a temperature of .pdf
Surface water entering the North Atlantic may have a temperature of .pdf
 
Suppose the rate of plant growth on Isle Royale supported an equilib.pdf
Suppose the rate of plant growth on Isle Royale supported an equilib.pdfSuppose the rate of plant growth on Isle Royale supported an equilib.pdf
Suppose the rate of plant growth on Isle Royale supported an equilib.pdf
 
Q1. public void operationZ() throws StackUnderflowException {   .pdf
Q1. public void operationZ() throws StackUnderflowException {   .pdfQ1. public void operationZ() throws StackUnderflowException {   .pdf
Q1. public void operationZ() throws StackUnderflowException {   .pdf
 
Print Calculator Question 18 of 20 Sapling Learning Map do ment of Lu.pdf
Print Calculator Question 18 of 20 Sapling Learning Map do ment of Lu.pdfPrint Calculator Question 18 of 20 Sapling Learning Map do ment of Lu.pdf
Print Calculator Question 18 of 20 Sapling Learning Map do ment of Lu.pdf
 
Part A 1. Solid product forms during the addition of the bleach solu.pdf
Part A 1. Solid product forms during the addition of the bleach solu.pdfPart A 1. Solid product forms during the addition of the bleach solu.pdf
Part A 1. Solid product forms during the addition of the bleach solu.pdf
 
Only 15 of the carbon-14 in a wooden bowl remains. How old is the b.pdf
Only 15 of the carbon-14 in a wooden bowl remains. How old is the b.pdfOnly 15 of the carbon-14 in a wooden bowl remains. How old is the b.pdf
Only 15 of the carbon-14 in a wooden bowl remains. How old is the b.pdf
 
Note Use Java Write a web server that is capable of processing only.pdf
Note Use Java Write a web server that is capable of processing only.pdfNote Use Java Write a web server that is capable of processing only.pdf
Note Use Java Write a web server that is capable of processing only.pdf
 
Negotiations are not usually faster in Deal focused cultures than re.pdf
Negotiations are not usually faster in Deal focused cultures than re.pdfNegotiations are not usually faster in Deal focused cultures than re.pdf
Negotiations are not usually faster in Deal focused cultures than re.pdf
 
9. The tort of assault and the tort of battery A) can occur independe.pdf
9. The tort of assault and the tort of battery A) can occur independe.pdf9. The tort of assault and the tort of battery A) can occur independe.pdf
9. The tort of assault and the tort of battery A) can occur independe.pdf
 
If law enforcement fails to give the defendant their Miranda rights,.pdf
If law enforcement fails to give the defendant their Miranda rights,.pdfIf law enforcement fails to give the defendant their Miranda rights,.pdf
If law enforcement fails to give the defendant their Miranda rights,.pdf
 
Identify one cyberattack that occurred in the last 2 years. What cau.pdf
Identify one cyberattack that occurred in the last 2 years. What cau.pdfIdentify one cyberattack that occurred in the last 2 years. What cau.pdf
Identify one cyberattack that occurred in the last 2 years. What cau.pdf
 
How do I add another txt.file to this Im trying to add this to be.pdf
How do I add another txt.file to this Im trying to add this to be.pdfHow do I add another txt.file to this Im trying to add this to be.pdf
How do I add another txt.file to this Im trying to add this to be.pdf
 
How you will respond empathetically, ethically, and legally to famil.pdf
How you will respond empathetically, ethically, and legally to famil.pdfHow you will respond empathetically, ethically, and legally to famil.pdf
How you will respond empathetically, ethically, and legally to famil.pdf
 
How can an insoluble salt with a basic anion be made to dissolve.pdf
How can an insoluble salt with a basic anion be made to dissolve.pdfHow can an insoluble salt with a basic anion be made to dissolve.pdf
How can an insoluble salt with a basic anion be made to dissolve.pdf
 
HELP IN JAVACreate a main method and use these input files to tes.pdf
HELP IN JAVACreate a main method and use these input files to tes.pdfHELP IN JAVACreate a main method and use these input files to tes.pdf
HELP IN JAVACreate a main method and use these input files to tes.pdf
 
Describe the steps in Sanger DNA sequencing. Provide a high level des.pdf
Describe the steps in Sanger DNA sequencing. Provide a high level des.pdfDescribe the steps in Sanger DNA sequencing. Provide a high level des.pdf
Describe the steps in Sanger DNA sequencing. Provide a high level des.pdf
 
Describe the advantages and disadvantages of the four standard acces.pdf
Describe the advantages and disadvantages of the four standard acces.pdfDescribe the advantages and disadvantages of the four standard acces.pdf
Describe the advantages and disadvantages of the four standard acces.pdf
 
d. Which of the following accounts should be reviewed by the auditor.pdf
d. Which of the following accounts should be reviewed by the auditor.pdfd. Which of the following accounts should be reviewed by the auditor.pdf
d. Which of the following accounts should be reviewed by the auditor.pdf
 

Recently uploaded

Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
AnaAcapella
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 

Recently uploaded (20)

psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
Magic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptxMagic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptx
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 

Jj_numjnamecityj1SorterParisj2PunchRomej3Reade.pdf

  • 6. s5 p6 j2 200 s5 p6 j4 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 (part’s 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 supplier’s total sales quantity and get the sales person’s 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 Adam’s location. Please update Smith’s 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 Smith’s 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
  • 7. 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. Note: You might need following setting before run your update SQL SET SQL_SAFE_UPDATES = 0; j_num jname city j1 Sorter Paris j2 Punch Rome j3 Reader Athens j4 Console Athens j5 Collator London j6 Terminal Oslo j7 Tape London Solution If you have any doubts, please give me comment... -- 1. Get supplier names and numbers for all suppliers who supplied part P3 and whose name begins with letter A.
  • 8. SELECT s_name, s_num FROM S INNER JOIN SPJ ON S.s_num = SPJ.s_num WHERE s_name LIKE 'A%' AND p_num = P3; -- 2. Get supplier names and numbers for all suppliers whose name (supplier name) begins with letter A and who supplied parts whose name (part’s name) begins with setter S. SELECT s_name, s_num FROM (S INNER JOIN SPJ ON S.s_num = SPJ.s_num) INNER JOIN P ON SPJ.p_num = P.p_num WHERE s_name LIKE 'A%' AND pname = 'S%'; -- 3. Get supplier names for suppliers who supplied for job J2. (Use a sub query) SELECT s_num FROM S WHERE s_num IN( SELECT s_num FROM SPJ WHERE j_num = 'j2' ); -- 4. Get supplier names for suppliers who supplied parts for jobs only in Athens. (Use sub query) SELECT s_num FROM (S INNER JOIN SPJ ON S.s_num = SPJ.s_num) INNER JOIN J ON SPJ.j_num = J.j_num WHERE J.city = 'Athens' AND s_num NOT IN( SELECT s_num FROM (S INNER JOIN SPJ ON S.s_num = SPJ.s_num) INNER JOIN J ON SPJ.j_num = J.j_num WHERE J.city <> 'Athens' ); -- 5. Get part names for parts that are not supplied for job J3. (Use a sub query) SELECT pname FROM P WHERE p_num NOT IN( SELECT p_num FROM SPJ WHERE p_num = 'j3' );
  • 9. -- 6. Get supplier numbers for suppliers with status lower than that of supplier S1. SELECT s_num FROM S WHERE status < ( SELECT status FROM S WHERE s_num = 's1' ); -- 7. Get supplier numbers and names for suppliers whose status is greater than status values of all suppliers in located Paris. SELECT s_num, sname FROM S WHERE status > ALL( SELECT status FROM S WHERE city = Paris ); -- 8. Calculate each supplier’s total sales quantity and get the sales person’s name if the sales person supplies parts more than 1000 units in total. SELECT S.s_num, s_name, SUM(qty) FROM S INNER JOIN SPJ ON S.s_num = SPJ.s_num GROUP BY S.s_num,s_name HAVING SUM(qty)>1000; -- 9. Get job numbers for jobs whose city is first in the alphabetical list of the job cities. SELECT j_num FROM J WHERE j_num IN( SELECT j_num FROM J ORDER BY city LIMIT 1 ); -- 10. Increase the status values of suppliers by 5 who are located in Paris. -- Please hand in the modified table and the query. UPDATE S SET status = status+5 WHERE city ='Paris'; SELECT *
  • 10. FROM S; -- 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. UPDATE P SET pname = 'Hammer' WHERE color = 'Red' AND city ='London' AND pname='Screw'; SELECT * FROM P; -- 12. Delete all jobs in Rome and all corresponding part shipments. (Please use 2 queries) -- Please hand in the modified table and the query. DELETE FROM SPJ WHERE j_num IN ( SELECT j_num FROM J WHERE city = 'Rome' ); DELETE FROM J WHERE city ='Rome'; -- 13. Smith moved to Adam’s location. Please update Smith’s city but do not use the city name directly. UPDATE S SET city = (SELECT city FROM S WHERE s_name='Adams') WHERE s_name='Smith'; -- 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) CREATE VIEW supplier_shipment AS SELECT s_num, SUM(qty) AS qty FROM SPJ GROUP s_num; -- 15. Please try to increase Smith’s 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) UPDATE supplier_shipment SET qty = qty +100; -- 16. Please create a base table supplier_shipment that shows each supplier and its total shipments from S and SPJ tables. DESCRIBE supplier_shipment;