Hot Deck 插補
建立一個名為 dbo.GetTripDistanceHotDeck 的函式,使用 Hot Deck 方法回傳 TripDistance 值。TripDistance 應具有精度 18、並保留 4 位小數。
本練習屬於課程
在 SQL Server 中撰寫函式與預存程序
練習說明
- 建立名為
dbo.GetTripDistanceHotDeck()的函式,回傳numeric資料型別。 - 從
YellowTripData的1000筆樣本中,選取第一個TripDistance值。 - 這
1000筆樣本只包含TripDistance大於 0 的紀錄。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
-- Create the function
___ ___ ___.___()
-- Specify return data type
___ ___(18,4)
AS
BEGIN
RETURN
-- Select the first TripDistance value
(___ TOP 1 ___
FROM YellowTripData
-- Sample 1000 records
TABLESAMPLE(1000 rows)
-- Only include records where TripDistance is > 0
___ ___ ___ ___)
END;