Question: Write the following queries in MySQL. Please submit the query and a snapshot of the result that you obtain in MySQL. (40 points) 1.Find the
Write the following queries in MySQL. Please submit the query and a snapshot of the result that you obtain in MySQL. (40 points)
1.Find the names of all suppliers and their addresses. Display the names in descending order.
2.Find the names of all suppliers and the name of parts that they supply. Display the names of suppliers in ascending order and the names of parts that each supplier supplies in descending order.
3.Display the names of all parts and their costs. The costs should be displayed in descending order.
4.Find the part names of parts for which there is some supplier.
create database A;
CREATE TABLE Suppliers ( sid int , sname varchar(80), address varchar(80), PRIMARY KEY (sid) );
CREATE TABLE Parts ( pid int , pname varchar(80), color varchar(80), PRIMARY KEY (pid) );
CREATE TABLE Catalog ( sid int, pid int, cost numeric(20,2), foreign key (sid) references Suppliers(sid), foreign key (pid) references Parts(pid), constraint PK_cat primary key (sid,pid) );
Insert into Suppliers(sname,address) values('Acme Widget Suppliers','"1 Grub St., Potemkin Village, IL 61801"'); Insert into Suppliers(sname,address) values('Big Red Tool and Die','"4 My Way, Bermuda Shorts, OR 90305"'); Insert into Suppliers(sname,address) values('Perfunctory Parts','"99999 Short Pier, Terra Del Fuego, TX 41299"'); Insert into Suppliers(sname,address) values('Alien Aircaft Inc.','"2 Groom Lake, Rachel, NV 51902"');
Insert into Parts(pname,color) values('Left Handed Bacon Stretcher Cover','Red'); Insert into Parts(pname,color) values('Smoke Shifter End','Black'); Insert into Parts(pname,color) values('Acme Widget Washer','Red'); Insert into Parts(pname,color) values('Acme Widget Washer','Silver'); Insert into Parts(pname,color) values('I Brake for Crop Circles Sticker','Translucent'); Insert into Parts(pname,color) values('Anti-Gravity Turbine Generator','Cyan'); Insert into Parts(pname,color) values('Anti-Gravity Turbine Generator','Magenta'); Insert into Parts(pname,color) values('Fire Hydrant Cap','Red'); Insert into Parts(pname,color) values('7 Segment Display','Green');
Insert into catalog(sid,pid,cost) values(1,3,'0.50'); Insert into catalog(sid,pid,cost) values(1,4,'0.50'); Insert into catalog(sid,pid,cost) values(1,8,'11.70'); Insert into catalog(sid,pid,cost) values(2,8,'7.95'); Insert into catalog(sid,pid,cost) values(2,1,'16.50'); Insert into catalog(sid,pid,cost) values(3,8,'12.50'); Insert into catalog(sid,pid,cost) values(3,9,'1.00'); Insert into catalog(sid,pid,cost) values(4,5,'2.20'); Insert into catalog(sid,pid,cost) values(4,6,'1247548.23'); Insert into catalog(sid,pid,cost) values(4,7,'1247548.23');
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
