Advertisement
Guest User

Untitled

a guest
Feb 26th, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.20 KB | None | 0 0
  1. --Assignment 12
  2. --Darryl Read
  3.  
  4. --Question 1
  5. declare @color varchar(50) = 'Blue'
  6.  
  7. if(@color is null OR @color = '')
  8. select count(ProductID) as 'Amount of Products',
  9. Round(avg(ListPrice),2) as 'Average',
  10. min(ListPrice) as 'Minimum',
  11. max(ListPrice) as 'Maximum'
  12. from AdventureWorksLT.SalesLT.Product
  13. else
  14. select count(ProductID) as 'Order Quantity',
  15. Round(avg(ListPrice),2) as 'Average',
  16. min(ListPrice) as 'Minimum',
  17. max(ListPrice) as 'Maximum',
  18. Color
  19. from AdventureWorksLT.SalesLT.Product
  20. where Color = @color
  21. group by Color
  22.  
  23.  
  24.  
  25. --Question 2
  26. declare @companyName varchar(50) = 'Bulk Discount Store'
  27.  
  28. select sum(OrderQty) as '# of Products',
  29. avg(UnitPrice) as 'Unit Price Avg',
  30. avg(UnitPriceDiscount) / avg(UnitPrice) * 100 as 'Avg Discount Price',
  31. sum(LineTotal) as 'Sum of all Products'
  32. from AdventureWorksLT.SalesLT.Customer as C
  33. inner join AdventureWorksLT.SalesLT.SalesOrderHeader as SOH
  34. on C.CustomerID = SOH.CustomerID
  35. inner join AdventureWorksLT.SalesLT.SalesOrderDetail as SOD
  36. on SOH.SalesOrderID = SOD.SalesOrderID
  37. where CompanyName = @companyName
  38.  
  39. --Question 3
  40. declare @StartDate datetime = '03/15/2004'
  41. declare @EndDate datetime = '01/01/2005'
  42.  
  43. select count(SalesOrderID),
  44. avg(TotalDue),
  45. max(DateDiff(day, OrderDate, ShipDate))
  46. from AdventureWorksLT.SalesLT.SalesOrderHeader
  47. where OrderDate > @StartDate AND OrderDate < @EndDate
  48.  
  49. --Question 4
  50.  
  51. select CompanyName as 'Company Name',
  52. sum(OrderQty) as ' Number of products'
  53. from AdventureWorksLT.SalesLT.Customer as C
  54. inner join AdventureWorksLT.SalesLT.SalesOrderHeader as SOH
  55. on C.CustomerID = SOH.CustomerID
  56. inner join AdventureWorksLT.SalesLT.SalesOrderDetail as SOD
  57. on SOH.SalesOrderID = SOD.SalesOrderID
  58. group by CompanyName
  59. order by sum(OrderQty) desc
  60.  
  61. --Question 5
  62.  
  63. select PC.Name as 'Product Category',
  64. Avg(P.ListPrice) as 'Average Price',
  65. Max(P.ListPrice) as 'Highest Price',
  66. Min(P.ListPrice) as 'Lowest Price',
  67. Count(ProductID) as 'Number of Products'
  68. from AdventureWorksLT.SalesLT.ProductCategory as PC
  69. inner join AdventureWorksLT.SalesLT.Product as P
  70. on PC.ProductCategoryID = P.ProductCategoryID
  71. group by PC.Name
  72. order by Count(ProductID) desc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement