Day 89 – Views
CREATE VIEW vwProductSales
AS
SELECT Products.ProductName, SUM(OrderDetails.Quantity) AS TotalSales
FROM Products
INNER JOIN OrderDetails ON Products.ProductID = OrderDetails.ProductID
GROUP BY Products.ProductName
HAVING SUM(OrderDetails.Quantity) > 1000
SELECT * FROM vwProductSales
In this example, a view named vwProductSales
is created to retrieve the total sales for each product and filter the results to only include products with total sales greater than 1000. The view is then queried using a standard SELECT
statement.