Describe how the query contained in the common table expression (CTE) works. Are correlated or uncorrelated subqueries
Question:
Describe how the query contained in the common table expression (CTE) works. Are correlated or uncorrelated subqueries leveraged? Are the query results filtered? If yes, how are the results filtered? Are table joins used in the query? If yes, what tables are linked together? Are aggregate functions leveraged in the query? If yes, describe what results are being sought along with the applicable grouping parameters.
USE BikeStores;
WITH BikeStores_Sales_CTE (BikeName, BikeSales, BikesSold) AS(
SELECT product_name,
(SELECT SUM(SOI1.quantity*SOI1.list_price)
FROM Sales.Order_Items SOI1
WHERE SOI1.product_id = PR.product_id) AS TotalSales,
(SELECT SUM(SOI2.quantity)
FROM Sales.Order_Items SOI2
WHERE SOI2.product_id = PR.product_id) AS BikesSold
FROM Production.Products PR
)
SELECT TOP 5 BikeName, BikeSales
FROM BikeStores_Sales_CTE
ORDER BY BikeSales DESC;
Concepts of Database Management
ISBN: 978-1285427102
8th edition
Authors: Philip J. Pratt, Mary Z. Last