哪种锻炼最能消耗卡路里?
新年将至,健身房即将迎来全年最忙的时段。为了激励会员,市场团队想为每位会员生成个性化内容,引导他们选择最有效的锻炼方式。他们需要您在 Snowflake 中构建一个透视表,按锻炼类型展示每位会员与每家健身房的平均卡路里消耗。祝您顺利完成!
本练习是课程的一部分
Snowflake 中的数据类型与函数
练习说明
- 创建名为
gym_workouts的 CTE,从visits表返回user_id、gym_id、workout_type、calories_burned,并从gyms表中返回gym_type为 'Premium' 的location。 - 从最终结果集中排除
gym_id字段。 - 对
gym_workouts临时结果集进行 PIVOT;对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 ___)
);