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

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 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"
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...
write php code for buying and selling web using sql, javascript ,html ,css style
write php code for buying and selling web using sql, javascript ,html ,css style
PHP/SQL Lab 1 Consider the banking example we used in the SQL in-class exercises: branch (branch-name,...
PHP/SQL Lab 1 Consider the banking example we used in the SQL in-class exercises: branch (branch-name, branch-city, assets) customer (customer-name, customer-street, customer-city) account (account-number, branch-name, balance) loan (loan-number, branch-name, amount) depositor (customer-name, account-number) borrower (customer-name, loan-number) Write PHP code for the following problems: 1. Create a php file to display the names and cities of customers who have an account at Downtown branch from the web. 2. Create the corresponding html and php files so that a user can insert...
write code to display "Hello terminal." On the terminal device with a name /dev/pts/1.
write code to display "Hello terminal." On the terminal device with a name /dev/pts/1.
IN SQL Create a table called product containing a product no, company name, model_no,product name. What...
IN SQL Create a table called product containing a product no, company name, model_no,product name. What is my primary key? Which datatypes should I use?Pleasesubmit a printout of the commands used for creating the above table and the resultsof your queries/commands
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT