Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Note: These problems make use of the Pine Valley Furniture Company database tabl

ID: 3737569 • Letter: N

Question

Note: These problems make use of the Pine Valley Furniture Company database tables. Write the appropriate SQL statement that either answers the questions or retrieves the requested values. Use the following for the date criteria: SUBSTRING(convert(varchar, orderdate, 126), 1, 7) ='2015-10' 7-51. Write a SQL query to list each customer who bought at least one product that belongs to product line Cherry Tree in October 2015. List each customer only once. 7-52. Modify 7-51 so that you include the number of products in product line Cherry Tree that the customer ordered in October 2015. 7-53. Modify 7-52 so that the list includes the number of products each customer bought in each product line in October 2015. 7-60. Produce a list of all the products (show product description) and the number of times each product has been ordered 7-65. Display the customer ID, name, and order ID for all customer orders. For those customers who do not have any orders, include them in the display once, with a 0 value for OrderID:

Explanation / Answer

Assume the Table Structures like below

Table1 : Customers

CustomerID CustomerName ContactName Address City PostalCode Country

Table2 : Orders

OrderID CustomerID EmployeeID OrderDate ShipperID

Table3 : Categories

CategoryID CategoryName Description

Table4 : Products

ProductID ProductName SupplierID CategoryID Unit Price

Table5 : Orders

OrderID CustomerID EmployeeID OrderDate ShipperID

7-51 : SELECT DISTINCT Customers.CustomerID FROM Customers,Products,Orders WHERE Products.ProductName='Cherry Tree' AND Customers.CustomerID=Orders.CustomerID AND SUBSTRING(convert(varchar, Orders.OrderDate, 126), 1, 7) ='2015-10'

7.52 : SELECT DISTINCT Customers.CustomerID,count(Orders.ProductName) FROM Customers,Products,Orders WHERE Products.ProductName='Cherry Tree' AND Customers.CustomerID=Orders.CustomerID AND SUBSTRING(convert(varchar, Orders.OrderDate, 126), 1, 7) ='2015-10'

7.53 : SELECT DISTINCT Customers.CustomerID,count(Orders.ProductID) FROM Customers,Products,Orders WHERE Customers.CustomerID=Orders.CustomerID AND SUBSTRING(convert(varchar, Orders.OrderDate, 126), 1, 7) ='2015-10'

7.60 : SELECT Products.ProductID,Products.ProductName,count(Products.ProductID) FROM Customers,Products,Orders WHERE Customers.CustomerID=Orders.CustomerID

7-65 : SELECT Customers.CustomerID,Customers.CustomerName,Orders.OrderID FROM Customers,Products,Orders WHERE Customers.CustomerID=Orders.CustomerID

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote