Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need the SQL code for each question. Here\'s the database script. -- super sim

ID: 3732166 • Letter: I

Question

I need the SQL code for each question. Here's the database script.

-- super simple distributor database
-- S is a supplier table, based in a city having a rating
-- P refers to Parts in distribution centers
--NOTE: A supplier can access and ship parts from various distribution cneters.
--That combination of Supplier and Part constitutes the SP table,  
-- rr 2018-03-15

drop table S;
drop table P;
drop table SP;
create table S(
sid Char(2) not null primary key,
sname Char(4) not null,
rating Int not null,
city Char(4) not null
);
insert into S values
('s1', 'SSSS', 20, 'Tucs'),
('s2', 'JJJJ', 10, 'Phox'),
('s3', 'BBBB', 30, 'Phox'),
('s4', 'CCCC', 20, 'Tucs'),
('s5', 'AAAA', 30, 'Flag')
;
create table P(
pid Char(2) not null primary key,
pname Char(4) not null,
weight Int not null,
city Char(4) not null
);
insert into P values
('p1', 'Nut', 12, 'Tucs'),
('p2', 'Bolt', 17, 'Phox'),
('p3', 'Scrw', 17, 'Casa'),
('p4', 'Scrw', 14, 'Tucs'),
('p5', 'Cam', 12, 'Phox'),
('p6', 'Cog', 19, 'Tucs')
;
create table SP(
sid Char(2) not null,
pid Char(2) not null,
qty Int not null,
Primary Key (sid, pid)
);
insert into SP values
('S1', 'P1', 300),
('S1', 'P2', 200),
('S1', 'P3', 400),
('S1', 'P4', 200),
('S1', 'P5', 100),
('S1', 'P6', 100),
('S2', 'P1', 300),
('S2', 'P2', 400),
('S3', 'P2', 200),
('S4', 'P2', 200),
('S4', 'P4', 300),
('S4', 'P5', 400)
;
Select S.sname, S.sid From S
Where Not Exists
( Select * From
SP Where
sp.sid = S.sid
And sp.pid ='P2');

Q1: Get Supplier numbers and names for suppliers in Tucson, i.e. ( Tucs) Q2: Get part numbers for all parts supplied where weight is less than 17 and not in Tucs Q3: For all parts, get the; part number, name, and the weight scaled by 5, label the column "Weight Q4: Get all combinations of supplier and part numbers together with their names, such that the suppliers are located. e same city an hum er is Q5: Get supplier id and name, for suppliers who supply part P3 Q6: For each part supplied, get the part number and the total quantity supplied, label that sum as "PartSum exclude shipments from supplier S1 Q7: Get part numbers for all parts supplied by two suppliers (Hint, this query involves Having)

Explanation / Answer

Answer 1:

select sid as Supplier_Number, sname as Supplier_Name from S where city='Tucs';

------------------------------------------------------------------------------------------------------------------

Answer 2:

select pid as Parts_Number from P where weight<17 and city<>'Tucs';

----------------------------------------------------------------------------------------------------------------

Answer 3:

select pid as Part_Number, pname as Part_Name, 5*weight as 5Weight from P;

----------------------------------------------------------------------------------------------------------------

Answer 4:

----------------------------------------------------------------------------------------------------------------

Answer 5:

select S.sid as Supplier_ID, S.sname as Supplier_Name from (select sid from SP where pid='P3') SP3

inner join S on S.sid = SP3.sid;

----------------------------------------------------------------------------------------------------------------

Answer 6:

select SPtmp.pid as Part_Number, sum(SPtmp.qty) as PartSum from (select * from SP where sid<>'S1') SPtmp group by SPtmp.pid;

-----------------------------------------------------------------------------------------------------------------

Answer 7:

select pid as Part_Number from SP group by pid having count(*)=2;

---------------------------------------------------------------------------------------------------------