Files
IPZ_1/nifi/sql/extract/05_fact_tournament.sql
2026-05-17 16:54:29 +02:00

19 lines
892 B
SQL

-- Returns one row per tournament with all natural keys needed for Oracle DIM lookups.
-- winner_org_id is NULL when the winner is an individual (Chess, StarCraft II, etc.)
SELECT
t.game_id,
CAST(DATE_FORMAT(t.start_date, '%Y%m%d') AS UNSIGNED) AS start_date_key,
CAST(DATE_FORMAT(t.end_date, '%Y%m%d') AS UNSIGNED) AS end_date_key,
o.organization_id AS winner_org_id,
t.event_name,
t.gender,
t.prize_pool_usd,
t.num_participants,
COALESCE(s.duration_days,
DATEDIFF(t.end_date, t.start_date) + 1) AS duration_days,
CASE WHEN t.club_championship_points = 1 THEN 1 ELSE 0
END AS has_club_points
FROM tournament t
LEFT JOIN schedule s ON t.tournament_id = s.tournament_id
LEFT JOIN organization o ON o.name = t.winner;