Aan de slagGa gratis aan de slag

Mean imputation

Create a stored procedure that will apply mean imputation to the YellowTripData records with an incorrect TripDistance of zero. The average trip distance variable should have a precision of 18 and 4 decimal places.

Deze oefening maakt deel uit van de cursus

Writing Functions and Stored Procedures in SQL Server

Cursus bekijken

Oefeninstructies

  • Create a stored procedure named cuspImputeTripDistanceMean
  • Create a numeric variable: @AvgTripDistance.
  • Compute the average TripDistance for all records where TripDistance is greater than 0.
  • Update the records in YellowTripData where TripDistance is 0 and set to @AvgTripDistance.

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

-- 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;
Code bewerken en uitvoeren