哪種訓練最能燃燒卡路里?
快到新年了,健身房即將進入最忙碌的時段。為了激勵會員,行銷團隊想為每位會員製作個人化內容,推動他們選擇最有效的訓練類型。他們需要你用 Snowflake 建立一個樞紐化的資料表,按訓練類型顯示各會員與健身房的平均消耗卡路里。加油!
本練習屬於課程
Snowflake 的資料型別與函式
練習說明
- 建立名為
gym_workouts的 CTE,從visits資料表取出user_id、gym_id、workout_type、calories_burned,並從gyms資料表取出gym_type為 'Premium' 的location。 - 從最終結果集中排除
gym_id欄位。 - 對
gym_workouts的暫時結果集進行樞紐分析;計算workout_type中各訓練類型的消耗卡路里總和。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
-- Create a CTE called gym_workouts returns the user_id, gym_id,
-- workout_type, calories_burned and location for 'Premium' gym types
___ ___ AS (
SELECT
visits.___,
visits.___,
visits.___,
visits.___,
___.___
FROM CORE_GYM.visits
JOIN CORE_GYM.gyms ON visits.gym_id = gyms.gym_id
WHERE ___
)
SELECT
-- Do NOT include the gym_id field in the final output
* ___ ___
FROM gym_workouts
-- Pivot gym_workouts, find the sum of calories_burned for each
-- type of workout in workout_type
___(
___(___)
___ ___ IN (ANY ORDER BY ___)
);