Creating your own Snowflake function
The development team is back again, thanks to all of your hard work from before. They'd like to create a "leader board" in the application to rank gym members by the efficiency of their workouts. Efficiency is determined by the number of calories that are burned per minute of working out. The first step to provide this data is creating a function to determine efficiency. Good luck!
Bu egzersiz
Data Types and Functions in Snowflake
kursunun bir parçasıdırEgzersiz talimatları
- Define a function called
calories_per_minutewith three parameters:start_timeandend_time, which are both of the typeTIMESTAMP, andcalories_burned, which is aNUMBER. - Further update the
calories_per_minutefunction to return aNUMBER. - Use the
DATEDIFFfunction to find the number of minutes between the check-in and checkout timestamps and divide by the number ofcalories_burnedto determine workout efficiency.
Uygulamalı interaktif egzersiz
Bu örnek kodu tamamlayarak bu egzersizi bitirin.
-- calories_per_minute should take a start_time, end_time, and calories_burned
CREATE OR REPLACE FUNCTION ___(
___ TIMESTAMP, ___ ___, calories_burned ___
)
-- Make sure the function returns a NUMBER
RETURNS ___
AS
$$
-- Use DATEDIFF to calculate the efficiency of a workout
___(MINUTE, start_time, end_time) / calories_burned
$$;