Which Transact-SQL successfully implements a CTE?

You are a database developer on an instance of SQL Server 2008. Your database contains the Product and ProductPriceHistory tables defined as follows:


You have a query that references a subquery on the two tables. You decide to use a Common Table Expression (CTE) instead of using a subquery.
Which Transact-SQL successfully implements a CTE?
A. WITH LowPricedProducts (ProductID, ProductName, Price)
AS
SELECT * FROM Product;
SELECT * FROM LowPricedProducts ORDER BY ProductName;
(SELECT p.ProductID,p.ProductName,MIN(c.Price)
FROM Product p INNER JOIN
ProductPriceHistory c ON c.ProductID = p.ProductID
GROUP BY p.ProductID, p.ProductName
HAVING MIN(c.Price) < 10
)
B. WITH LowPricedProducts (ProductID, ProductName, Price)
AS
(SELECTp.ProductID,p.ProductName,MIN(c.Price)
FROM Product p INNER JOIN
ProductPriceHistory c ON c.ProductID = p.ProductID
GROUP BY p.ProductID, p.ProductName
HAVING MIN(c.Price) < 10
)
SELECT * FROM LowPricedProducts ORDER BY ProductName;
C. SELECT p.ProductID, p.ProductName, MIN(c.Price)
FROM Product p INNER JOIN
ProductPriceHistory c ON c.ProductID = p.ProductID
GROUP BY p.ProductID, p.ProductName
HAVING MIN(c.Price) < 10
OUTPUT * INTO LowPricedProducts )
SELECT *
FROM LowPricedProducts
ORDER BY ProductName;
D. WITH LowPricedProducts (ProductID, ProductName, Price)
AS
SELECT * FROM LowPricedProducts ORDER BY ProductName;
(SELECTp.ProductID,p.ProductName,MIN(c.Price)
FROM Product p INNER JOIN
ProductPriceHistory c ON c.ProductID = p.ProductID
GROUP BY p.ProductID, p.ProductName
ORDER BY p.ProductName
HAVING MIN(c.Price) < 10)

microsoft-exams

Leave a Reply

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.