Bắt đầu ngayBắt đầu miễn phí

Xác định thành viên xuất sắc

Bảng xếp hạng thì còn gì vui hơn? Nhóm vận hành muốn dùng dữ liệu trong schema CORE_GYM để tạo bảng xếp hạng thành viên dựa trên lượng calo đốt cháy. Để làm điều này, họ trông cậy vào bạn tạo một tập kết quả kết hợp hai bảng membersvisits.

Bài tập này là một phần của khóa học

Kiểu dữ liệu và Hàm trong Snowflake

Xem khóa học

Hướng dẫn bài tập

  • Dùng một CTE để tạo tập kết quả tạm thời tên flattened_members lấy user_id, tên và họ từ bảng members.
  • Định nghĩa tập kết quả tạm thời thứ hai tên high_performers trả về tất cả bản ghi trong bảng visitscalories_burned > 500.
  • JOIN đầu ra của flattened members với high_performers theo trường user_id.

Bài tập tương tác thực hành trực tiếp

Hãy thử làm bài tập này bằng cách hoàn thành đoạn mã mẫu này.

-- Retrieves the user_id, first name, and last name from the members table
___ ___ ___ (
    SELECT
        user_id,
        personal_info:name.___ AS first_name,
        personal_info:name.___ AS last_name,
    FROM CORE_GYM.members),
  
-- high_performers should return all visits where > 500 calories were burned
___ ___ (
    SELECT 
        user_id,
        TO_DATE(checkin_time) AS workout_date,
        workout_type,
        calories_burned
    FROM CORE_GYM.visits
    WHERE ___)

SELECT
    CONCAT(flattened_members.first_name, ' ', flattened_members.last_name) AS full_name,
    high_performers.workout_date,
    high_performers.workout_type,
    high_performers.calories_burned
FROM high_performers
-- JOIN flattened_members to high_performers on the user_id field
JOIN ___ ON ___.___ = high_performers.user_id;
Chỉnh sửa và Chạy Mã