Question: Given Schema: customer: ( cus_code :integer , cus_lname:varchar(20), cus_fname:varchar(20), cus_initial:char, cus_areacode:integer,cus_phone:integer). invoice: ( inv_number :integer , cus_code:integer, inv_date:date, foreign key cus_code references customer(cus_code)) line: (

Given Schema:

customer: (cus_code:integer, cus_lname:varchar(20), cus_fname:varchar(20), cus_initial:char, cus_areacode:integer,cus_phone:integer).

invoice: (inv_number:integer, cus_code:integer, inv_date:date,

foreign key cus_code references customer(cus_code))

line: (inv_number:integer, prod_code:integer ,line_units:integer,

foreign key (inv_number) references Invoice(inv_number),

foreign key (prod_code) references Product (prod_code) )

product:(prod_code:integer, prod_desc:varchar(50), prod_price:integer, prod_quant:integer,vend_code:integer,

foreign key (vend_code) referenecs Vendor(vend_code))

vendor:(vend_code:integer,vend_name:varchar(30),vend_contact:varchar(30),vend_areacode:integer,vend_phone:integer)

customer:

10010, Ramas, Paul, A, 615, 8442573

10011, Dunne, Leona, K, 713, 8941238

10012, Smith, Kathy, W, 615, 8942285

10013, Olowski, Paul,F, 615, 2221672

10014, Orlando, Myron, NULL, 615, 2971228

invoice:

1001, 10011, 2018-01-03

1002, 10014, 2016-08-04

1003, 10012, 2017-03-20

1004, 10014, 2018-01-13

line:

1001, 12321, 1

1001, 65781, 3

1003, 83456, 2

1002, 34256, 6

1003, 12321, 5

1002, 12321, 6

1001, 83456, 3

product:

12321, hammer, 189 ,20, 232

65781, chain, 12, 45, 235

34256, tape, 35, 60, 235

83456, saw, 165, 15, 236

12333, hanger, 200 ,10, 232

vendor:

232, Bryson, Smith, 615, 2233234

235, SuperLoo, Anderson, 615, 2158995

236, Brett, Manko, 612, 3458695

Write SQL statements to answer the following questions

1- Find how many vendors supplied products that have a quantity lower than 60?

2- For each vendor, find their product that has the lowest product price. Your output should include vendor code, vendor name, product name and product price for each vendor.

3- Find how many products are there in each invoice. The output should include invoice number and number of products (not the number of line_units) in the invoice.

4- Find how many products are supplied by each vendor. The output should be a list of vend_code and for each vend_code, the number of products sold by this vendor.

5- Find the total value for all products in the inventory supplied by vendor Bryson. The total value in the inventory is the sum of product quantity * product price for all products listed in the product table.

6- Find unique customer code, customer last name for all invoices.

7- Find product description, price, and vendor code for the product with the lowest quantity.

8- Create a view Paul that contains customer code, customer last name, and number of invoices for each customer who has a first name of Paul.

9- For each invoice in 2018, find the total price. The total invoice price is the sum of product price* line units for each product purchased in the invoice.

10- Find how many products are bought by each customer. The output should be a list of cus_code and for each cus_code, the number of products purchased by this customer. A more complex query (if you want to try it), would be to list the name of the customer, along with the cus_code.

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 Databases Questions!