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

PLEASE GIVE IT A THUMBS UP, I SERIOUSLY NEED ONE, IF YOU NEED ANY MODIFICATION THEN LET ME KNOW, I WILL DO IT FOR YOU
AS I DONE MOST OF YOUR ANSWERS, THOUGH WE ARE ONLY ALLOWED TO ATTEMPT ONE ANSWER OR FOUR SUB PARTS, PLEASE GIVE IT A THUMBS UP

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...
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...
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 the code in Java: 1. Create a method that displays your name in the console....
Write the code in Java: 1. Create a method that displays your name in the console. This method is void and takes no parameters. Make an app that runs the method in response to a button press. 2. Create a version of the method in #1 that takes the text (String) to be displayed as a parameter. Allow the user to enter the text in a dialog box or text field and display that text in the console. Be sure...
SQL Code: Write a script that creates and calls a stored procedure named test. This procedure...
SQL Code: Write a script that creates and calls a stored procedure named test. This procedure should identify all of the prime numbers less than 100. (A prime number is an integer that can't be divided by another integer other than 1 and itself.) Then, it should display a string variable that includes the prime numbers like this: 2 1 3 1 5 1 7 1 1 1 1 1 3 1 1 7 1 1 9 1 2 3...
SQL ONLY. WRITE CLEAR AND CORRECT ANSWERS. Consider the following relations (PRIMARY KEYS ARE WRITTEN IN...
SQL ONLY. WRITE CLEAR AND CORRECT ANSWERS. Consider the following relations (PRIMARY KEYS ARE WRITTEN IN BOLD) departments (dept_no, dept_name) dept_emp (emp_no, dept_no, from_date, to_date) dept_manager (dept_no, emp_no, from_date, to_date) employees (emp_no, birth_date, first_name, last_name, gender, hire_date) salaries (emp_no, salary, from_date, to_date) titles(emp_no, title, from_date, to_date) Write the following queries in SQL. No duplicates should be printed in any of the answers. List all the titles for which there is at least one employee having the title. Find the current...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT