Inline TVF
Create an inline table value function that returns the number of rides and total ride duration for each StartStation where the StartDate of the ride is equal to the input parameter.
Den här övningen är en del av kursen
Writing Functions and Stored Procedures in SQL Server
Övningsinstruktioner
- Create a function named
SumStationStatsthat has one input parameter of typedatetime-@StartDate- and returns aTABLEdata type. - Calculate the total
RideCountusingCOUNT()andID. - Calculate the
TotalDurationusingSUM()andDURATION. - Group by
StartStation.
Interaktiv övning med praktiskt arbete
Testa den här övningen genom att slutföra den här exempelkoden.
-- Create the function
___ ___ SumStationStats(___ AS ___)
-- Specify return data type
___ ___
AS
RETURN
SELECT
StartStation,
-- Use COUNT() to select RideCount
___(___) AS RideCount,
-- Use SUM() to calculate TotalDuration
___(___) AS TotalDuration
FROM CapitalBikeShare
WHERE CAST(StartDate as Date) = @StartDate
-- Group by StartStation
___ ___ ___;