Get startedGet started for free

Calculating mode (II)

In the last exercise, you created a CTE which assigned row numbers to each unique value in OrderPrice. All you need to do now is to find the OrderPrice with the highest row number.

This exercise is part of the course

Intermediate SQL Server

View Course

Exercise instructions

Use the CTE ModePrice to return the value of OrderPrice with the highest row number.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

-- CTE from the previous exercise
WITH ModePrice (OrderPrice, UnitPriceFrequency)
AS
(
	SELECT OrderPrice,
	ROW_NUMBER() 
    OVER (PARTITION BY OrderPrice ORDER BY OrderPrice) AS UnitPriceFrequency
	FROM Orders
)

-- Select the order price from the CTE
SELECT ___ AS ModeOrderPrice
FROM ___
-- Select the maximum UnitPriceFrequency from the CTE
WHERE UnitPriceFrequency IN (___ ___(___) FROM ___)
Edit and Run Code