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,

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;

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Computer Network Questions!