Question: Create SQL statements for the following queries based on Use the Purchase schema: 1 . List full details of all products. 2 . List full
Create SQL statements for the following queries based on Use the Purchase schema:
List full details of all products.
List full details of all products with red PRODTYPE.
List the names and addresses of all suppliers whose SUPSTATUS is not NULL,
alphabetically ordered by name.
List all products with a quantity below in ascending order of quantity.
List the supplies for which no purchase price has been specified.
How many products each supplier supplies?
What is the average price of all products each supplier supplies?
What is the maximum delivery period for all products?
List the details of suppliers and products of which more than one suppliers
supply the same product.
How many different SUPPLIERS have made purchase in APRIL?
List the price and type of all products supplied by Deliwines
How many products each supplier supplies?
List the details of all suppliers supplying Chateau Petrus
How many Chateau Cheval Blanc has been purchased in May?
How many Chateau Cheval Blanc has been purchased each month?
Tips: use EXTRACT functions to group records in a table by month.
List the suppliers that currently didnt supply any products.
List the products that are currently unsupplied by any supplier.
List the number of products of different product types.
What is the maximum and minimum quantity for each purchase order in April?
What is the most commonly purchased product product with the highest
quantity in POLine for each month?
For each question, list the SQL statements and corresponding screenshots.
Using this information for the SQL database
CREATE TABLE SUPPLIER
SUPNR CHAR NOT NULL PRIMARY KEY,
SUPNAME VARCHAR NOT NULL,
SUPADDRESS VARCHAR
SUPCITY VARCHAR
SUPSTATUS SMALLINT;
CREATE TABLE PRODUCT
PRODNR CHAR NOT NULL PRIMARY KEY,
PRODNAME VARCHAR NOT NULL,
CONSTRAINT UC UNIQUEPRODNAME
PRODTYPE VARCHAR
CONSTRAINT CC CHECKPRODTYPE IN white 'red', 'rose','sparkling'
AVAILABLEQUANTITY INTEGER;
CREATE TABLE SUPPLIES
SUPNR CHAR NOT NULL,
PRODNR CHAR NOT NULL,
PURCHASEPRICE NUMBER
DELIVPERIOD INT,
PRIMARY KEY SUPNR PRODNR
FOREIGN KEY SUPNR REFERENCES SUPPLIER SUPNR
ON DELETE CASCADE,
FOREIGN KEY PRODNR REFERENCES PRODUCT PRODNR
ON DELETE CASCADE;
comment on column SUPPLIES.PURCHASEPRICE IS 'PURCHASEPRICE IN EUR';
comment on column SUPPLIES.DELIVPERIOD IS 'DELIVPERIOD IN DAYS';
CREATE TABLE PURCHASEORDER
PONR CHAR NOT NULL PRIMARY KEY,
PODATE DATE,
SUPNR CHAR NOT NULL,
FOREIGN KEY SUPNR REFERENCES SUPPLIER SUPNR
ON DELETE CASCADE;
CREATE TABLE POLINE
PONR CHAR NOT NULL,
PRODNR CHAR NOT NULL,
QUANTITY INTEGER,
PRIMARY KEY PONR PRODNR
FOREIGN KEY PONR REFERENCES PURCHASEORDER PONR
ON DELETE CASCADE,
FOREIGN KEY PRODNR REFERENCES PRODUCT PRODNR
ON DELETE CASCADE;
INSERT INTO SUPPLIERSUPNR SUPNAME, SUPADDRESS, SUPCITY, SUPSTATUS VALUES 'Deliwines', Avenue of the Americas', 'New York', ;
INSERT INTO SUPPLIERSUPNR SUPNAME, SUPADDRESS, SUPCITY, SUPSTATUS VALUES 'Best Wines', Market Street', 'San Francisco', ;
INSERT INTO SUPPLIERSUPNR SUPNAME, SUPADDRESS, SUPCITY, SUPSTATUS VALUESAd Fundum', Wacker Drive', 'Chicago', ;
INSERT INTO SUPPLIERSUPNR SUPNAME, SUPADDRESS, SUPCITY, SUPSTATUS VALUES 'Spirits co Strip', 'Las Vegas', ;
INSERT INTO SUPPLIERSUPNR SUPNAME, SUPADDRESS, SUPCITY, SUPSTATUS VALUES 'The Wine Depot', Montgomery Street', 'San Francisco', ;
INSERT INTO SUPPLIERSUPNR SUPNAME, SUPADDRESS, SUPCITY, SUPSTATUS VALUES 'Vinos del Mundo', Collins Avenue', 'Miami', ;
INSERT INTO SUPPLIERSUPNR SUPNAME, SUPADDRESS, SUPCITY, SUPSTATUS VALUES 'Wine Trade Logistics', Rhode Island Avenue', 'Washington', ;
INSERT INTO SUPPLIERSUPNR SUPNAME, SUPADDRESS, SUPCITY, SUPSTATUS VALUES 'The Wine Crate', McKinney Avenue', 'Dallas', ;
INSERT INTO PRODUCTPRODNRPRODNAME,PRODTYPE,AVAILABLEQUANTITY VALUES 'Chateau Miraval, Cotes de Provence Rose, 'rose', ;
INSERT INTO PRODUCTPRODNRPRODNAME,PRODTYPE,AVAILABLEQUANTITY VALUES 'Chateau Haut Brion, 'red', ;
INSERT INTO PRODUCTPRODNRPRODNAME,PRODTYPE,AVAILABLEQUANTITY VALUES 'Meerdael, Methode Traditionnelle Chardonnay, 'sparkling', ;
INSERT INTO PRODUCTPRODNRPRODNAME,PRODTYPE,AVAILABLEQUANTITY VALUES 'Chateau Petrus, 'red', ;
INSERT INTO PRODUCTPRODNRPRODNAME,PRODTYPE,AVAILABLEQUANTITY VALUES 'Jacques Selosse, Brut Initial, 'sparkling', ;
INSERT INTO PRODUCTPRODNRPRODNAME,PRODTYPE,AVAILABLEQUANTITY VALUES 'BillecartSalmon, Brut Rserve 'sparkling', ;
INSERT INTO PRODUCTPRODNRPRODNAME,PRODTYPE,AVAILABLEQUANTITY VALUES 'Marques de Caceres, Rioja Crianza, 'red', ;
IN
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
