開始使用免費開始

評估運動時長

私人教練希望依照學員的實際情況來「調整」課程長度。他們想更了解使用者在健身房針對各種訓練類型所花費的平均時間。這能幫助他們決定每種課程的合適長度。

本練習屬於課程

Snowflake 的資料型別與函式

檢視課程

練習說明

  • 建立一個名為 workout_durations 的 CTE,從 CORE_GYM.visits 資料表回傳 gym_idworkout_type,以及計算後的 workout_length
  • 將結果進行 pivot,產生一個結果集,顯示每個健身房與各訓練類型的平均 workout_length

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

-- Create a CTE called workout_durations to prepare data to be pivoted
___ ___ ___ (
    SELECT
        gym_id,
        workout_type,
        DATEDIFF(MINUTES, checkin_time, checkout_time) AS workout_length
    ___ ___.___
)

SELECT
    *
FROM workout_durations

-- Pivot the results, find the average workout length for each gym and workout type
___(
    ___(___) 
    ___ ___ IN (ANY ORDER BY workout_type)
);
編輯並執行程式碼