5. Create a view named CustomerAddresses that shows the shipping and billing add
ID: 662908 • Letter: 5
Question
5. Create a view named CustomerAddresses that shows the shipping and billing addresses for each customer
This view should return these columns from the Customers table: CustomerID, EmailAddress, LastName and FirstName.
This view should return these columns from the Addresses table: BillLine1, BillLine2, BillCity, BillState, BillZip, ShipLine1, ShipLine2, ShipCity, ShipState, and ShipZip.
Write a SELECT statement that returns these columns from the CustomerAddresses view that you created in exercise 1: CustomerID, LastName, FirstName, BillLine1.
6. Ceate a view named OrderItemProducts that returns columns from the Orders, OrderItems, and Products tables.
This view should return these columns from the Orders table: OrderID, OrderDate, TaxAmount, and ShipDate.
This view should return these columns from the OrderItems table: ItemPrice, DiscountAmount, FinalPrice (the discount amount subtracted from the item price), Quantity, and ItemTotal (the calculated total for the item).
This view should return the ProductName column from the Products table.
7. Write an UPDATE statement that updates the CustomerAddresses view you created in exercise 1 so it sets the first line of the shipping address to 1990 Westwood Blvd. for the customer with an ID of 8.
8. Create a view named ProductSummary that uses the view you created in exercise 4. This view should return some summary information about each product.
Each row should include these columns: ProductName, OrderCount (the number of times the product has been ordered), and OrderTotal (the total sales for the product).
9. Write a SELECT statement that uses the view that you created in question 8 to get total sales for the five best selling products.
Explanation / Answer
5. create view [CustomerAddresses] as select c.CustomerID, LastName, FirstName, BillLine1 from
Customers c, Addresses a where c.CustomerID=a.CustomerID;
6. create view [OrderItemProducts ] as select o.OrderID, OrderDate, TaxAmount, ShipDate,ItemPrice, DiscountAmount,
ItemPrice-DiscountAmount as FinalPrice,Quantity, (ItemPrice-DiscountAmount)*Quantity as ItemTotal,ProductName
from Orders o,OrderItems oi,Products p where o.OrderID=oi.OrderID and oi.ProductID=p.ProductID
NOTE : FOR Q.7 EXERCISE 1 IS REQUIRED, FOR Q.8 & 9 EXERCISE 4 IS REUIRED. ITS BETTER YOU PROVIDE THE FULL EXERCISE ALONG WITH TABLE STRUCTURE FOR BETTER AND QUICK ANSWER.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.