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:
1. List full details of all products.
2. List full details of all products with red PRODTYPE.
3. List the names and addresses of all suppliers whose SUPSTATUS is not NULL,
alphabetically ordered by name.
4. List all products with a quantity below 50, in ascending order of quantity.
5. List the supplies for which no purchase price has been specified.
6. How many products each supplier supplies?
7. What is the average price of all products each supplier supplies?
8. What is the maximum delivery period for all products?
9. List the details of suppliers and products of which more than one suppliers
supply the same product.
10. How many different SUPPLIERS have made purchase in APRIL?
11. List the price and type of all products supplied by Deliwines.
12. How many products each supplier supplies?
13. List the details of all suppliers supplying Chateau Petrus.
14. How many Chateau Cheval Blanc has been purchased in May?
15. How many Chateau Cheval Blanc has been purchased each month?
Tips: use EXTRACT() functions to group records in a table by month.
16. List the suppliers that currently didnt supply any products.
17. List the products that are currently unsupplied by any supplier.
18. List the number of products of different product types.
19. What is the maximum and minimum quantity for each purchase order in April?
20. What is the most commonly purchased product (product with the highest
quantity in PO_Line) 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(4) NOT NULL PRIMARY KEY,
SUPNAME VARCHAR(40) NOT NULL,
SUPADDRESS VARCHAR(50),
SUPCITY VARCHAR(20),
SUPSTATUS SMALLINT);
CREATE TABLE PRODUCT
(PRODNR CHAR(6) NOT NULL PRIMARY KEY,
PRODNAME VARCHAR(60) NOT NULL,
CONSTRAINT UC1 UNIQUE(PRODNAME),
PRODTYPE VARCHAR(10),
CONSTRAINT CC1 CHECK(PRODTYPE IN ('white', 'red', 'rose','sparkling')),
AVAILABLE_QUANTITY INTEGER);
CREATE TABLE SUPPLIES
(SUPNR CHAR(4) NOT NULL,
PRODNR CHAR(6) NOT NULL,
PURCHASE_PRICE NUMBER(8,2),
DELIV_PERIOD 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.PURCHASE_PRICE IS 'PURCHASE_PRICE IN EUR';
comment on column SUPPLIES.DELIV_PERIOD IS 'DELIV_PERIOD IN DAYS';
CREATE TABLE PURCHASE_ORDER
(PONR CHAR(7) NOT NULL PRIMARY KEY,
PODATE DATE,
SUPNR CHAR(4) NOT NULL,
FOREIGN KEY (SUPNR) REFERENCES SUPPLIER (SUPNR)
ON DELETE CASCADE);
CREATE TABLE PO_LINE
(PONR CHAR(7) NOT NULL,
PRODNR CHAR(6) NOT NULL,
QUANTITY INTEGER,
PRIMARY KEY (PONR, PRODNR),
FOREIGN KEY (PONR) REFERENCES PURCHASE_ORDER (PONR)
ON DELETE CASCADE,
FOREIGN KEY (PRODNR) REFERENCES PRODUCT (PRODNR)
ON DELETE CASCADE);
INSERT INTO SUPPLIER(SUPNR, SUPNAME, SUPADDRESS, SUPCITY, SUPSTATUS) VALUES('21', 'Deliwines', '240, Avenue of the Americas', 'New York', '20');
INSERT INTO SUPPLIER(SUPNR, SUPNAME, SUPADDRESS, SUPCITY, SUPSTATUS) VALUES('32', 'Best Wines', '660, Market Street', 'San Francisco', '90');
INSERT INTO SUPPLIER(SUPNR, SUPNAME, SUPADDRESS, SUPCITY, SUPSTATUS) VALUES('37','Ad Fundum', '82, Wacker Drive', 'Chicago', '95');
INSERT INTO SUPPLIER(SUPNR, SUPNAME, SUPADDRESS, SUPCITY, SUPSTATUS) VALUES('52', 'Spirits co.','928, Strip', 'Las Vegas', '');
INSERT INTO SUPPLIER(SUPNR, SUPNAME, SUPADDRESS, SUPCITY, SUPSTATUS) VALUES('68', 'The Wine Depot', '132, Montgomery Street', 'San Francisco', '10');
INSERT INTO SUPPLIER(SUPNR, SUPNAME, SUPADDRESS, SUPCITY, SUPSTATUS) VALUES('69', 'Vinos del Mundo', '4, Collins Avenue', 'Miami', '92');
INSERT INTO SUPPLIER(SUPNR, SUPNAME, SUPADDRESS, SUPCITY, SUPSTATUS) VALUES('84', 'Wine Trade Logistics', '1002, Rhode Island Avenue', 'Washington', '92');
INSERT INTO SUPPLIER(SUPNR, SUPNAME, SUPADDRESS, SUPCITY, SUPSTATUS) VALUES('94', 'The Wine Crate', '330, McKinney Avenue', 'Dallas', '75');
INSERT INTO PRODUCT(PRODNR,PRODNAME,PRODTYPE,AVAILABLE_QUANTITY) VALUES('0119', 'Chateau Miraval, Cotes de Provence Rose, 2015', 'rose', '126');
INSERT INTO PRODUCT(PRODNR,PRODNAME,PRODTYPE,AVAILABLE_QUANTITY) VALUES('0154', 'Chateau Haut Brion, 2008', 'red', '111');
INSERT INTO PRODUCT(PRODNR,PRODNAME,PRODTYPE,AVAILABLE_QUANTITY) VALUES('0178', 'Meerdael, Methode Traditionnelle Chardonnay, 2014', 'sparkling', '136');
INSERT INTO PRODUCT(PRODNR,PRODNAME,PRODTYPE,AVAILABLE_QUANTITY) VALUES('0185', 'Chateau Petrus, 1975', 'red', '5');
INSERT INTO PRODUCT(PRODNR,PRODNAME,PRODTYPE,AVAILABLE_QUANTITY) VALUES('0199', 'Jacques Selosse, Brut Initial, 2012', 'sparkling', '96');
INSERT INTO PRODUCT(PRODNR,PRODNAME,PRODTYPE,AVAILABLE_QUANTITY) VALUES('0212', 'Billecart-Salmon, Brut Rserve,2014', 'sparkling', '141');
INSERT INTO PRODUCT(PRODNR,PRODNAME,PRODTYPE,AVAILABLE_QUANTITY) VALUES('0219', 'Marques de Caceres, Rioja Crianza, 2010', 'red', '0');
IN

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Accounting Questions!