Question

In: Computer Science

Write the correct code in SQL 1. What is the name and address of the customer...

Write the correct code in SQL

1. What is the name and address of the customer that placed order 57?

2. Assume there is only one product with the description Cherry End Table. List the names of the raw materials that go into making that product.

3. List the product id, description, and finish of the least expensive products. (Note: A couple of rows show a price of 0. Exclude products with a price of 0 from your query.)

4. How many orders did each customer from New York state (i.e. NY) place? List the answers in order from the most to the least orders.

5. What are the cheapest oak-finished products?

6. Which products in product lines 2 or 4 are more expensive than the most expensive birch-finished product? List the results in order by product id.

7. Assume there is only one customer named Contemporary Casuals. What products has Contemporary Casuals ordered? Include the product id and product description in your answer and order your answer by product id.

8. Based on customer id (and no other information about a customer), how many of the product 48” Bookcase (in any finish) did each customer order? Only include customers in your answer who ordered at least 4 such items.

9. How many raw materials are used in each product? Order your answers by product id. (Note: Based on the limited data in the database, you should only find six products included in your answer.)

10. How many raw materials are used in each product? Only include materials supplied by vendor 2. Order your answers by product id. (Hint: You will need the supplies table but not the vendor table to answer this question.)

Tables and Fields in Database db_pvfc12_big

(Note: The use of fields in Teradata SQL is not case sensitive.)

CUSTOMER_T

           Customerid

           Customername

           Customeraddress

           Customercity

           Customerstate

           Customerpostalcode

PRODUCT_T

           Productid

           Productdescription

           Productfinish

           Productstandardprice

           Productonhand

           Productlineid

RAWMATERIAL_T

           Materialid

           Materialname

           Thickness

           Width

           Size

           Material

           Materialstandardprice

           Unitofmeasure

           Materialtype

ORDER_T

           Orderid

           Orderdate

           Customerid

           Fulfillmentdate

           Salespersonid

           Shipadrsid

ORDERLINE_T

           Orderlineid

           Orderid

           Productid

           Orderedquantity

USES_T

           Productid

           Materialid

           Quantityrequired

SUPPLIES_T

           Vendorid

           Materialid

           Supplyunitprice

Solutions

Expert Solution

Solution:

The SQL queries have been given below.

  • The zero priced items have been excluded, for the calculation of "least price" in all such queries.

Kindly run and confirm if you require any additional information.

Hope that helps.

1. What is the name and address of the customer that placed order 57?

Select c.Customername,c.Customeraddress
From CUSTOMER_T c
INNER JOIN ORDER_T o
    ON ( c.Customerid = o.Customerid )
WHERE o.Orderid = 57 ;

2. Assume there is only one product with the description Cherry End Table. List the names of the raw materials that go into making that product.

Select r.Materialname
From PRODUCT_T p
INNER JOIN USES_T u
    ON (p.Productid = u.Productid)
INNER JOIN RAWMATERIAL_T r
    ON (u.Materialid = r.Materialid)
WHERE p.Productdescription = 'Cherry End Table' ;

3. List the product id, description, and finish of the least expensive products. (Note: A couple of rows show a price of 0. Exclude products with a price of 0 from your query.)

Select  Productid,
Productdescription,
Productfinish
From PRODUCT_T
Where  Productstandardprice =
  (Select min(Productstandardprice) from PRODUCT_T
   WHERE PRODUCT_T.Productstandardprice != 0 ) ;

4. How many orders did each customer from New York state (i.e. NY) place? List the answers in order from the most to the least orders.

Select c.Customername, c.Customerid,
count(o.Orderid) numorders
From CUSTOMER_T c
INNER JOIN ORDER_T o
    ON ( c.Customerid = o.Customerid )
WHERE c.customerstate = 'NY'
Group by c.Customername,c.Customerid
ORDER BY numorders DESC ;

5. What are the cheapest oak-finished products?

Select  Productid,
Productdescription,
Productfinish
From PRODUCT_T
Where  Productstandardprice =
  (Select min(Productstandardprice) from PRODUCT_T p
       WHERE  p.Productstandardprice != 0 ) 
and  Productfinish = 'Oak';

6. Which products in product lines 2 or 4 are more expensive than the most expensive birch-finished product? List the results in order by product id.

Select pp.productid, pp.Productdescription from PRODUCT_T pp 
where 
pp.productlineid in (2, 4) and 
pp.Productstandardprice > 
(
  Select max(p.Productstandardprice) maxprice 
  From PRODUCT_T p
  where p.Productfinish = 'birch'
)
order by pp.productid
;

7. Assume there is only one customer named Contemporary Casuals. What products has Contemporary Casuals ordered? Include the product id and product description in your answer and order your answer by product id.

Select p.productid,p.Productdescription
From CUSTOMER_T c
INNER JOIN ORDER_T o 
     on ( c.Customerid = o.Customerid)
INNER JOIN ORDERLINE_T ot 
     on (o.Orderid = ot.Orderid)
INNER JOIN PRODUCT_T p 
    on (ot.productid = p.productid)
where c.Customername = 'Contemporary Casuals' 
order by productid ;

8. Based on customer id (and no other information about a customer), how many of the product 48” Bookcase (in any finish) did each customer order? Only include customers in your answer who ordered at least 4 such items.

Select c.Customerid, count(p.productid) numproducts
From CUSTOMER_T c
INNER JOIN ORDER_T o 
     on ( c.Customerid = o.Customerid)
INNER JOIN ORDERLINE_T ot 
     on (o.Orderid = ot.Orderid)
INNER JOIN PRODUCT_T p 
    on (ot.productid = p.productid)
where p.Productdescription = '48” Bookcase' 
Group by c.Customerid
Having  count(p.productid) >= 4;

9. How many raw materials are used in each product? Order your answers by product id. (Note: Based on the limited data in the database, you should only find six products included in your answer.)

Select p.productid,p.Productdescription,
count(r.Materialid) nummaterialsused
from PRODUCT_T p
   INNER JOIN USES_T u
    ON (p.Productid = u.Productid)
   INNER JOIN RAWMATERIAL_T r
    ON (u.Materialid = r.Materialid)
Group by p.productid,p.Productdescription
Order by p.productid;

10. How many raw materials are used in each product? Only include materials supplied by vendor 2. Order your answers by product id. (Hint: You will need the supplies table but not the vendor table to answer this question.)

Select p.productid,p.Productdescription,
count(r.Materialid) nummaterialsused
from PRODUCT_T p
   INNER JOIN USES_T u
    ON (p.Productid = u.Productid)
   INNER JOIN RAWMATERIAL_T r
    ON (u.Materialid = r.Materialid)
   INNER JOIN SUPPLIES_T s 
    ON (r.Materialid = s.Materialid)
where s.Vendorid = 2
Group by p.productid,p.Productdescription
Order by p.productid;

Related Solutions

Write the correct code in SQL 1. What is the name and address of the customer...
Write the correct code in SQL 1. What is the name and address of the customer that placed order 57? 2. Assume there is only one product with the description Cherry End Table. List the names of the raw materials that go into making that product. 3. List the product id, description, and finish of the least expensive products. (Note: A couple of rows show a price of 0. Exclude products with a price of 0 from your query.) 4....
1. Write the SQL code required to list the employee number, first and last name, middle...
1. Write the SQL code required to list the employee number, first and last name, middle initial, and the hire date. Sort your selection by the hire date, to display the newly hired employees first. 2. Modify the previous query and list the employee first, last name and middle initial as one column with the title EMP_NAME. Make sure the names are listed in the following format: First name, space, initial, space, last name (e.g. John T Doe). Hint: use...
SQL statmen: List the first name, the last name, the address, the city, the state, the...
SQL statmen: List the first name, the last name, the address, the city, the state, the branchNo, and the email of agents working in the branch B005 and having email addresses ending with extensions different from .com.
Write and run SQL statements to complete the following tasks. Show customer 10014’s name and the...
Write and run SQL statements to complete the following tasks. Show customer 10014’s name and the product’s descriptions which he/she purchased and the number of units of each. Add a new attribute (column) engaged varchar(3) to the customer table and update the engaged attribute for the customers who have not generated any invoice to ‘No’. Task 2 should be completed in two steps i.e. two SQL commands. Sql file -- Creating Tables .headers on .mode column .separator , DROP TABLE...
Write a Java program which asks customer name, id, address and other personal information, there are...
Write a Java program which asks customer name, id, address and other personal information, there are two types of customers, walk-in and credit card. The rates of items are different for both type of customers. System also asks for customer type. Depending upon customer type, it calculates total payment. A credit-card customer will pay 5 % extra the actual price. Use object-oriented concepts to solve the problem. Define as many items and prices as you want. Example Output: Enter Name...
Write a javascript code to Create a function called Hotel that takes Room no, Customer name....
Write a javascript code to Create a function called Hotel that takes Room no, Customer name. amount paid. Write a code to call hotel function for each customer and display details of customers lodging in rooms with even room numbers. I need only js and html code. no css pls take screenshot of output , else I might dislike thanks
1. Write a query in SQL to find the full name of the “Actors” who appeared...
1. Write a query in SQL to find the full name of the “Actors” who appeared in the movie titled Star Wars (using JOIN ). 2.Write a SQL query to find the movie Title that has received Lowest rating from reviewers, but whose actors have received an award for their contribution in movie. (Expected Output: Fantastic Beasts and Where to Find Them) 3.Write a SQL query that display the list of genres, Number of movies in that genre grouped by...
Consider the following relational schema: Salerep(sales_rep_ID, name, address, commission, rate) Customer(customer_number, name, address, balance, credit_limit, sales_rep_ID)...
Consider the following relational schema: Salerep(sales_rep_ID, name, address, commission, rate) Customer(customer_number, name, address, balance, credit_limit, sales_rep_ID) Part(part_number, part_description, on_hand, class, warehouse, price) Orders(order_number, order_date, customer_number) Orderlilne(order_number, part_number, number_order) Write SQL statements for the following queries: a) Produce a list showing part_number, part_description, on_hand, and price sorted by part_description. b) List customer’s name followed by order_number, part_description, and number_order. c) List names of customers who have ordered the most expensive item(Hint: Use a nested SQL query to determine thehighest price.) d)...
write a sql statement that retrieves product ID (ProductID) and name (Name) from Production.product table for...
write a sql statement that retrieves product ID (ProductID) and name (Name) from Production.product table for all product whose name includes both the words "silver" and "frame"
write exactly what the following code prints. Ensure that you write in the correct order. clearly...
write exactly what the following code prints. Ensure that you write in the correct order. clearly distinguish scratch work from your final answer. Public class Base{ public void m1(Base a){ System.out.println("Base m1"); a.m2(); } public void m2(){ System.out.println("Base m2"); } } Public class Derived1 extends Base{ public void m1(Base b){ System.out.println("Derived1 m1"); } public void m2(){ System.out.println("Derived1 m2"); } } Public class Derived2 extends Base{ public void m2(){ System.out.m2(){ System.out.println("Dertived2 m2"); } } public class UserBaseAndDerived1And2{ public static void main(String[]...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT