SQLUSA

Microsoft SQL Server 2000 Best Practices

 

How to create VIEWs for low and high-priced products?

 

Execute the following script in Query Analyzer to create the views:

 

CREATE VIEW [LowPriceProducts] AS
SELECT ProductName,UnitPrice
FROM Products
WHERE UnitPrice < 1.0 / 3.0 * (SELECT AVG(UnitPrice) FROM Products)
GO
SELECT * FROM LowPriceProducts ORDER BY ProductName
GO

CREATE VIEW [HighPriceProducts] AS
SELECT ProductName,UnitPrice
FROM Products
WHERE UnitPrice > 2.0 / 3.0 * (SELECT AVG(UnitPrice) FROM Products)
GO
SELECT * FROM HighPriceProducts ORDER BY ProductName
GO

 

The World Leader in SQL Server Training
 
SQLUSA.com Home Page