Hot Deck Imputation
สร้างฟังก์ชันชื่อ dbo.GetTripDistanceHotDeck ที่คืนค่า TripDistance ด้วยวิธี Hot Deck โดย TripDistance ควรมีความแม่นยำ 18 หลัก และทศนิยม 4 ตำแหน่ง
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
การเขียนฟังก์ชันและ Stored Procedures ใน SQL Server
คำแนะนำการฝึกหัด
- สร้างฟังก์ชันชื่อ
dbo.GetTripDistanceHotDeck()ที่คืนค่าเป็นชนิดข้อมูลnumeric - เลือกค่า
TripDistanceแรกจากตัวอย่างข้อมูล1000แถวของตารางYellowTripData - ตัวอย่างข้อมูล
1000แถวนี้ควรรวมเฉพาะแถวที่TripDistanceมากกว่าศูนย์เท่านั้น
แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ
ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์
-- 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;