开始使用免费开始使用

哪种锻炼最能消耗卡路里?

新年将至,健身房即将迎来全年最忙的时段。为了激励会员,市场团队想为每位会员生成个性化内容,引导他们选择最有效的锻炼方式。他们需要您在 Snowflake 中构建一个透视表,按锻炼类型展示每位会员与每家健身房的平均卡路里消耗。祝您顺利完成!

本练习是课程的一部分

Snowflake 中的数据类型与函数

查看课程

练习说明

  • 创建名为 gym_workouts 的 CTE,从 visits 表返回 user_idgym_idworkout_typecalories_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 ___)
);
编辑并运行代码