Saturday, February 12, 2011

SQL-Ice Cream Assignment--Part 2

The sale, distributors, and inventory queries of an ice cream shop database.\/\/\/

 Select flavName, brandName, saleScoops, salePrice, saleDate  
 From dbo.iceCreamSales S  
      inner join dbo.xrefIceCreamSalesxFlavorBrand xS  
      on S.saleId = xS.salesId  
      inner join dbo.xrefIceCreamFlavorxBrand xF  
      on xS.xrefFlavId = xF.xrefFlavId  
      inner join dbo.iceCreamFlavor F  
      on xF.flavId = F.flavId  
      inner join dbo.iceCreamBrand B  
      on xF.brandId = B.brandId  
 Go
This is the sales query, showing the sale, how many scoops, what date, and when a sale of a flavor and brand has happened.

 Select tubsOnHand, flavName, brandName  
 From dbo.iceCreamInventory I  
      Inner Join dbo.xrefIceCreamInventoryxFlavorBrand xI  
      on I.invenId = xI.invenId  
      inner join dbo.xrefIceCreamFlavorxBrand xF  
      on xI.xrefFlavId = xF.xrefFlavId  
      inner join dbo.iceCreamFlavor F  
      on xF.flavId = F.flavId  
      inner join dbo.iceCreamBrand B  
      on xF.brandId = B.brandId  
 Where tubsOnHand <= 1  
 Go
This is the Inventory query, showing where there is one or less tubs left on had for all flavor and brands.

 Select distrName, flavName, brandName  
 From iceCreamDistributor D  
      Inner Join dbo.xrefIceCreamDistributorxFlavorBrand xD  
      on D.distrID= xD.distrId  
      inner join dbo.xrefIceCreamFlavorxBrand xF  
      on xD.xrefFlavId = xF.xrefFlavId  
      inner join dbo.iceCreamFlavor F  
      on xF.flavId = F.flavId  
      inner join dbo.iceCreamBrand B  
      on xF.brandId = B.brandId  
 where B.brandId=1 and F.flavId=2  
 Go  
This is the Distriubtors query, found by brand and flavor combination.

No comments:

Post a Comment