Professional Documents
Culture Documents
each bike name and associated total quantity sold. Then query the view to
show the top ten bikes sold. Present the output in descending order based on
total bikes sold
USE [BikeStores]
GO
CREATE VIEW TotalBikesSoldView
AS
SELECT [product_name],SUM(quantity) AS Quantity
FROM [BikeStores].[sales].[order_items]As O, [BikeStores].[production].[products] AS P
WHERE O.product_id=P.product_id
GROUP BY product_name
GO
GO
--EXECUTE THE PROCEDURE
EXEC GetBikeCategoriesWithMinPriceBelowValue @Price=500;
Problem 9: Create a stored procedure that lists the stock quantity for each
bike category at a specified store. The output must show the bike category
and stock quantity value. The results need to be presented in ascending order
based on the bike category. The skeleton of the stored procedure is provided
below.
USE BikeStores;
GO
CREATE PROCEDURE GetCategoryStockQuantityForStore
@StoreName VARCHAR(255)
AS
SET NOCOUNT ON;
SELECT [category_name],
SUM([quantity]) AS NumBikes
FROM [BikeStores].[production].[categories] AS C,[BikeStores].[production].[stocks] AS
S,[BikeStores].[production].[products] AS P,[sales].[stores] AS St
WHERE S.product_id = P.product_id AND C.category_id=P.category_id AND St.store_id =
S.store_id AND store_name = @StoreName
GROUP BY category_name
GO