Which code segment should you use?

CORRECT TEXT
You have a database that contains the tables as shown in the exhibit. (Click the Exhibit button.)

You need to create a query that returns a list of products from Sales.ProductCatalog. The solution
must meet the following requirements:
UnitPrice must be returned in descending order.
The query must use two-part names to reference the table.
The query must use the RANK function to calculate the results.
The query must return the ranking of rows in a column named PriceRank.
The list must display the columns in the order that they are defined in the table.
PriceRank must appear last.
Which code segment should you use?
To answer, type the correct code in the answer area.

CORRECT TEXT
You have a database that contains the tables as shown in the exhibit. (Click the Exhibit button.)

You need to create a query that returns a list of products from Sales.ProductCatalog. The solution
must meet the following requirements:
UnitPrice must be returned in descending order.
The query must use two-part names to reference the table.
The query must use the RANK function to calculate the results.
The query must return the ranking of rows in a column named PriceRank.
The list must display the columns in the order that they are defined in the table.
PriceRank must appear last.
Which code segment should you use?
To answer, type the correct code in the answer area.

Answer: See the explanation

Explanation:
SELECT ProductCatalog.CatID, ProductCatalog.CatName, ProductCatalog.ProductID,
ProductCatalog.ProdName, ProductCatalog.UnitPrice,
RANK() OVER (ORDER BY ProductCatalog.UnitPrice DESC) AS PriceRank
FROM Sales.ProductCatalog
ORDER BY ProductCatalog.UnitPrice DESC



Leave a Reply 5

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


LL-Thomas

LL-Thomas

Select ProductName, UnitPrice, RANK() OVER (ORDER BY UnitPrice desc) as PriceRank
From Sales.ProductCatalog
Oreder by ProductId, UnitPrice desc

Will

Will

SELECT ProductCatalog.CatID, ProductCatalog.CatName, ProductCatalog.ProductID,
ProductCatalog.ProdName, ProductCatalog.UnitPrice,
RANK() OVER (ORDER BY ProductCatalog.UnitPrice DESC) AS PriceRank
FROM Sales.ProductCatalog

Seems to be suficient. The “Order by” is made in the OVER already…

henrov

henrov

SELECT p.PRODUCTNAME, — a list of products, more was not asked….
RANK(p.Unitprice) OVER (ORDER BY UnitPrce DESC) as PriceRank
FROM Sales.ProductCatalog as P
Order by p.nNitprice DESC

lewis

lewis

select CatID,CatName,ProductID,ProdName,UnitPrice,
rank () over (over by UnitPrice desc) as PriceRank
from Sales.ProductCatalog

Google

Google

Sites of interest we’ve a link to.