開始使用免費開始

計算眾數(II)

在上一個練習中,你建立了 CTE,為 OrderPrice 的每個唯一值指派了列號。現在你只需要找出擁有最高列號的 OrderPrice

本練習屬於課程

SQL Server 中級

檢視課程

練習說明

使用 CTE ModePrice 傳回擁有最高列號的 OrderPrice 值。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

-- 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 ___)
編輯並執行程式碼