开始使用免费开始使用

均值插补

创建一个存储过程,对 YellowTripDataTripDistance 错误为 0 的记录执行均值插补。平均行程距离变量的精度应为 18,且保留 4 位小数。

本练习是课程的一部分

SQL Server 中的函数与存储过程编写

查看课程

练习说明

  • 创建名为 cuspImputeTripDistanceMean 的存储过程。
  • 创建一个数值变量:@AvgTripDistance
  • 计算所有 TripDistance 大于 0 的记录的平均 TripDistance
  • 更新 YellowTripDataTripDistance0 的记录,并将其设为 @AvgTripDistance

交互式实操练习

通过完成这段示例代码来试试这个练习。

-- Create the stored procedure
___ ___ dbo.___
AS
BEGIN
-- Specify @AvgTripDistance variable
___ ___ AS numeric (18,4)

-- Calculate the average trip distance
___ ___ = ___(___) 
FROM YellowTripData
-- Only include trip distances greater than 0
___ ___ ___ ___

-- Update the records where trip distance is 0
___ ___
___ ___ =  ___
WHERE ___ = _
END;
编辑并运行代码