-- Returns one row per player-medal with natural keys and pre-computed measures.
SELECT
    t.game_id,
    m.country_id,
    m.organization_id,
    m.medal                                                     AS medal_type,
    CAST(DATE_FORMAT(t.start_date, '%Y%m%d') AS UNSIGNED)      AS date_key,
    m.player_name,
    1                                                           AS medal_count,
    CASE m.medal
        WHEN 'Gold'   THEN 3
        WHEN 'Silver' THEN 2
        ELSE               1
    END                                                         AS medal_points
FROM medalist m
JOIN tournament t ON m.tournament_id = t.tournament_id;
