
CREATE OR REPLACE PROCEDURE tcg.public.USP_TCG_Statistic_Calc (
      a_comment TEXT
    , a_guid UUID
    , a_user_id INT
	, OUT o_success BOOLEAN
)
LANGUAGE plpgsql
AS $$
DECLARE
	v_change_set_id INT;
	v_commander_damage_limit INT := 21;
    v_comment TEXT;
    v_deck_entity_type_code TEXT := 'deck';
	v_guid UUID;
    v_no_permission_error_type_id INT;
	v_time_start TIMESTAMP;
    v_user_deck_link_entity_type_code TEXT := 'user_deck_link';
    v_user_entity_type_code TEXT := 'user';
	v_user_id INT;
	v_warning_error_type_id INT;
BEGIN
	v_comment = TRIM(COALESCE(a_comment, ''));
	v_guid = a_guid;
	v_user_id = a_user_id;

	v_no_permission_error_type_id := (SELECT ERROR_TYPE.error_type_id FROM tcg.public.Error_Type ERROR_TYPE WHERE ERROR_TYPE.code = 'NO_PERMISSION' LIMIT 1);
	v_time_start := CURRENT_TIMESTAMP;
	v_warning_error_type_id := (SELECT ERROR_TYPE.error_type_id FROM tcg.public.Error_Type ERROR_TYPE WHERE ERROR_TYPE.code = 'WARNING' LIMIT 1);

	DROP TABLE IF EXISTS Temp_Statistic_Calc_Statistic;
	DROP TABLE IF EXISTS Temp_Statistic_Calc_Deck;
	DROP TABLE IF EXISTS Temp_Statistic_Calc_Game;
	DROP TABLE IF EXISTS Temp_Statistic_Calc_Player;
	DROP TABLE IF EXISTS Temp_Statistic_Calc_User;
	DROP TABLE IF EXISTS Temp_Statistic_Calc_User_Deck_Link;
	DROP TABLE IF EXISTS Temp_Statistic_Calc_Round;
	DROP TABLE IF EXISTS Temp_Statistic_Calc_Round_Player_Damage;
    DROP TABLE IF EXISTS Temp_Statistic_Calc_Player_Round_Link;
	DROP TABLE IF EXISTS Temp_Statistic_Calc_Error;

    CREATE TEMP TABLE Temp_Statistic_Calc_Statistic (
          temp_statistic_id INT GENERATED ALWAYS AS IDENTITY
        , entity_type_code TEXT
        , entity_record_id TEXT
        , name TEXT NOT NULL
        , value_bool BOOLEAN
        , value_float DOUBLE PRECISION
        , value_interval INTERVAL
        , value_text TEXT
        , value_timestamp TIMESTAMP
        , is_bool BOOLEAN
        , is_float BOOLEAN
        , is_interval BOOLEAN
        , is_text BOOLEAN
        , is_timestamp BOOLEAN
        , active BOOLEAN
    );

    CREATE TEMP TABLE Temp_Statistic_Calc_Deck (
          deck_id INT NOT NULL
        , name TEXT
        , is_commander BOOLEAN
        , commander_bracket_id INT
        , active BOOLEAN
        , created_on TIMESTAMP
        , created_by_user_id INT
        , updated_last_on TIMESTAMP
        , updated_last_by_user_id INT
        , change_set_id INT
        
        , count_games INT
        , count_games_won INT
        , count_games_lost INT
        , win_lose_ratio FLOAT
        , best_position INT
        , worst_position INT
        , total_damage_received INT
        , mean_total_damage_received FLOAT
        , max_total_damage_received INT
        , min_total_damage_received INT
        , total_damage_received_game_win INT
        , mean_total_damage_received_game_win FLOAT
        , max_total_damage_received_game_win INT
        , min_total_damage_received_game_win INT
        , total_damage_received_game_lose INT
        , mean_total_damage_received_game_lose FLOAT
        , max_total_damage_received_game_lose INT
        , min_total_damage_received_game_lose INT
        , total_commander_damage_dealt INT
        , mean_total_commander_damage_dealt FLOAT
        , max_total_commander_damage_dealt INT
        , min_total_commander_damage_dealt INT
        , total_commander_damage_dealt_game_won INT
        , mean_total_commander_damage_dealt_won FLOAT
        , max_total_commander_damage_dealt_won INT
        , min_total_commander_damage_dealt_won INT
        , total_commander_damage_dealt_game_lost INT
        , mean_total_commander_damage_dealt_lost FLOAT
        , max_total_commander_damage_dealt_lost INT
        , min_total_commander_damage_dealt_lost INT
        , total_commander_damage_received INT
        , mean_total_commander_damage_received FLOAT
        , max_total_commander_damage_received INT
        , min_total_commander_damage_received INT
        , total_commander_damage_received_game_won INT
        , mean_total_commander_damage_received_won FLOAT
        , max_total_commander_damage_received_won INT
        , min_total_commander_damage_received_won INT
        , total_commander_damage_received_game_lost INT
        , mean_total_commander_damage_received_lost FLOAT
        , max_total_commander_damage_received_lost INT
        , min_total_commander_damage_received_lost INT
        , total_life_gained INT
        , mean_total_life_gained FLOAT
        , max_total_life_gained INT
        , min_total_life_gained INT
        , total_life_gained_game_won INT
        , mean_total_life_gained_game_won FLOAT
        , max_total_life_gained_game_won INT
        , min_total_life_gained_game_won INT
        , total_life_gained_game_lost INT
        , mean_total_life_gained_game_lost FLOAT
        , max_total_life_gained_game_lost INT
        , min_total_life_gained_game_lost INT
        , total_game_round_count INT
        , mean_game_round_count FLOAT
        , lowest_game_round_count INT
        , highest_game_round_count INT
        , total_game_win_round_count INT
        , mean_game_win_round_count FLOAT
        , lowest_game_win_round_count INT
        , highest_game_win_round_count INT
        , total_game_lose_round_count INT
        , mean_game_lose_round_count FLOAT
        , lowest_game_lose_round_count INT
        , highest_game_lose_round_count INT
        , total_game_round_survived_count INT
        , mean_game_round_survived_count FLOAT
        , lowest_game_round_survived_count INT
        , highest_game_round_survived_count INT
        , total_game_win_round_survived_count INT
        , mean_game_win_round_survived_count FLOAT
        , lowest_game_win_round_survived_count INT
        , highest_game_win_round_survived_count INT
        , total_game_lose_round_survived_count INT
        , mean_game_lose_round_survived_count FLOAT
        , lowest_game_lose_round_survived_count INT
        , highest_game_lose_round_survived_count INT
        , total_game_duration INTERVAL
        , mean_game_duration INTERVAL
        , shortest_game_duration INTERVAL
        , longest_game_duration INTERVAL
        , total_game_win_duration INTERVAL
        , mean_game_win_duration INTERVAL
        , shortest_game_win_duration INTERVAL
        , longest_game_win_duration INTERVAL
        , total_game_lose_duration INTERVAL
        , mean_game_lose_duration INTERVAL
        , shortest_game_lose_duration INTERVAL
        , longest_game_lose_duration INTERVAL
        , total_commander_deaths INT
        , mean_commander_deaths FLOAT
        , max_commander_deaths INT
        , min_commander_deaths INT
        , total_commander_deaths_game_won INT
        , mean_commander_deaths_game_won FLOAT
        , max_commander_deaths_game_won INT
        , min_commander_deaths_game_won INT
        , total_commander_deaths_game_lost INT
        , mean_commander_deaths_game_lost FLOAT
        , max_commander_deaths_game_lost INT
        , min_commander_deaths_game_lost INT
        , total_pod_sizes INT
        , total_opponents_faced INT
        , mean_pod_size FLOAT
        , max_pod_size INT
        , min_pod_size INT
        , total_pod_sizes_won INT
        , total_opponents_beaten INT
        , mean_pod_size_won FLOAT
        , max_pod_size_won INT
        , min_pod_size_won INT
        , total_pod_sizes_lost INT
        , total_opponents_lost_to INT
        , mean_pod_size_lost FLOAT
        , max_pod_size_lost INT
        , min_pod_size_lost INT
        , latest_game_win_on TIMESTAMP
        , latest_game_win_pod_size INT
        , latest_game_lose_on TIMESTAMP
        , latest_game_lose_pod_size INT
        , archenemy_deck_id INT
        , rival_deck_id INT
        , archenemy_player_id INT
        , rival_player_id INT
    );
    
    CREATE TEMP TABLE Temp_Statistic_Calc_Game (
          game_id INT NOT NULL
        , notes TEXT
        , is_commander BOOLEAN
        , is_draft BOOLEAN
        , is_sealed BOOLEAN
        , location_name TEXT
        , start_on TIMESTAMP
        , end_on TIMESTAMP
        , starting_life INT
        , active BOOLEAN
        , created_on TIMESTAMP
        , created_by_user_id INT
        , updated_last_on TIMESTAMP
        , updated_last_by_user_id INT
        , change_set_id INT

        , max_round_display_order INT
        , count_players INT
        , duration INTERVAL
    );

    CREATE TEMP TABLE Temp_Statistic_Calc_Player (
          player_id INT
        , game_id INT
        , user_id INT
        , deck_id INT
        , name TEXT
        , notes TEXT
        , display_order INT
        , active BOOLEAN

        , round_display_order_eliminated INT
        , final_player_damage_round_id INT
        , placement INT
        , max_total_commander_damage_received INT
        , total_commander_damage_dealt INT
        , total_damage_received INT
        , total_life_gained INT
        , total_commander_deaths INT
    );

    CREATE TEMP TABLE Temp_Statistic_Calc_User (
          user_id INT NOT NULL
        , user_auth0_id TEXT
        , firstname TEXT
        , surname TEXT
        , email TEXT
        , is_email_verified BOOLEAN
        , is_super_user BOOLEAN
        , active BOOLEAN
        , created_on TIMESTAMP
        , created_by_user_id INT
        , updated_last_on TIMESTAMP
        , updated_last_by_user_id INT
        , change_set_id INT

        , count_games INT
        , count_games_won INT
        , count_games_lost INT
        , win_lose_ratio FLOAT
        , best_position INT
        , worst_position INT
        , total_damage_received INT
        , mean_total_damage_received FLOAT
        , max_total_damage_received INT
        , min_total_damage_received INT
        , total_damage_received_game_win INT
        , mean_total_damage_received_game_win FLOAT
        , max_total_damage_received_game_win INT
        , min_total_damage_received_game_win INT
        , total_damage_received_game_lose INT
        , mean_total_damage_received_game_lose FLOAT
        , max_total_damage_received_game_lose INT
        , min_total_damage_received_game_lose INT
        , total_commander_damage_dealt INT
        , mean_total_commander_damage_dealt FLOAT
        , max_total_commander_damage_dealt INT
        , min_total_commander_damage_dealt INT
        , total_commander_damage_dealt_game_won INT
        , mean_total_commander_damage_dealt_won FLOAT
        , max_total_commander_damage_dealt_won INT
        , min_total_commander_damage_dealt_won INT
        , total_commander_damage_dealt_game_lost INT
        , mean_total_commander_damage_dealt_lost FLOAT
        , max_total_commander_damage_dealt_lost INT
        , min_total_commander_damage_dealt_lost INT
        , total_commander_damage_received INT
        , mean_total_commander_damage_received FLOAT
        , max_total_commander_damage_received INT
        , min_total_commander_damage_received INT
        , total_commander_damage_received_game_won INT
        , mean_total_commander_damage_received_won FLOAT
        , max_total_commander_damage_received_won INT
        , min_total_commander_damage_received_won INT
        , total_commander_damage_received_game_lost INT
        , mean_total_commander_damage_received_lost FLOAT
        , max_total_commander_damage_received_lost INT
        , min_total_commander_damage_received_lost INT
        , total_life_gained INT
        , mean_total_life_gained FLOAT
        , max_total_life_gained INT
        , min_total_life_gained INT
        , total_life_gained_game_won INT
        , mean_total_life_gained_game_won FLOAT
        , max_total_life_gained_game_won INT
        , min_total_life_gained_game_won INT
        , total_life_gained_game_lost INT
        , mean_total_life_gained_game_lost FLOAT
        , max_total_life_gained_game_lost INT
        , min_total_life_gained_game_lost INT
        , total_game_round_count INT
        , mean_game_round_count FLOAT
        , lowest_game_round_count INT
        , highest_game_round_count INT
        , total_game_win_round_count INT
        , mean_game_win_round_count FLOAT
        , lowest_game_win_round_count INT
        , highest_game_win_round_count INT
        , total_game_lose_round_count INT
        , mean_game_lose_round_count FLOAT
        , lowest_game_lose_round_count INT
        , highest_game_lose_round_count INT
        , total_game_round_survived_count INT
        , mean_game_round_survived_count FLOAT
        , lowest_game_round_survived_count INT
        , highest_game_round_survived_count INT
        , total_game_win_round_survived_count INT
        , mean_game_win_round_survived_count FLOAT
        , lowest_game_win_round_survived_count INT
        , highest_game_win_round_survived_count INT
        , total_game_lose_round_survived_count INT
        , mean_game_lose_round_survived_count FLOAT
        , lowest_game_lose_round_survived_count INT
        , highest_game_lose_round_survived_count INT
        , total_game_duration INTERVAL
        , mean_game_duration INTERVAL
        , shortest_game_duration INTERVAL
        , longest_game_duration INTERVAL
        , total_game_win_duration INTERVAL
        , mean_game_win_duration INTERVAL
        , shortest_game_win_duration INTERVAL
        , longest_game_win_duration INTERVAL
        , total_game_lose_duration INTERVAL
        , mean_game_lose_duration INTERVAL
        , shortest_game_lose_duration INTERVAL
        , longest_game_lose_duration INTERVAL
        , total_commander_deaths INT
        , mean_commander_deaths FLOAT
        , max_commander_deaths INT
        , min_commander_deaths INT
        , total_commander_deaths_game_won INT
        , mean_commander_deaths_game_won FLOAT
        , max_commander_deaths_game_won INT
        , min_commander_deaths_game_won INT
        , total_commander_deaths_game_lost INT
        , mean_commander_deaths_game_lost FLOAT
        , max_commander_deaths_game_lost INT
        , min_commander_deaths_game_lost INT
        , total_pod_sizes INT
        , total_opponents_faced INT
        , mean_pod_size FLOAT
        , max_pod_size INT
        , min_pod_size INT
        , total_pod_sizes_won INT
        , total_opponents_beaten INT
        , mean_pod_size_won FLOAT
        , max_pod_size_won INT
        , min_pod_size_won INT
        , total_pod_sizes_lost INT
        , total_opponents_lost_to INT
        , mean_pod_size_lost FLOAT
        , max_pod_size_lost INT
        , min_pod_size_lost INT
        , latest_game_win_on TIMESTAMP
        , latest_game_win_pod_size INT
        , latest_game_lose_on TIMESTAMP
        , latest_game_lose_pod_size INT
        , archenemy_deck_id INT
        , rival_deck_id INT
        , archenemy_player_id INT
        , rival_player_id INT
    );

    CREATE TEMP TABLE Temp_Statistic_Calc_User_Deck_Link (
          user_id INT NOT NULL
        , deck_id INT NOT NULL
        
        , count_games INT
        , count_games_won INT
        , count_games_lost INT
        , win_lose_ratio FLOAT
        /*
        , mean_mulligan_count INT
        , max_mulligan_count INT
        , min_mulligan_count INT
        */
        , best_position INT
        , worst_position INT
        , total_damage_received INT
        , mean_total_damage_received FLOAT
        , max_total_damage_received INT
        , min_total_damage_received INT
        , total_damage_received_game_win INT
        , mean_total_damage_received_game_win FLOAT
        , max_total_damage_received_game_win INT
        , min_total_damage_received_game_win INT
        , total_damage_received_game_lose INT
        , mean_total_damage_received_game_lose FLOAT
        , max_total_damage_received_game_lose INT
        , min_total_damage_received_game_lose INT
        , total_commander_damage_dealt INT
        , mean_total_commander_damage_dealt FLOAT
        , max_total_commander_damage_dealt INT
        , min_total_commander_damage_dealt INT
        , total_commander_damage_dealt_game_won INT
        , mean_total_commander_damage_dealt_won FLOAT
        , max_total_commander_damage_dealt_won INT
        , min_total_commander_damage_dealt_won INT
        , total_commander_damage_dealt_game_lost INT
        , mean_total_commander_damage_dealt_lost FLOAT
        , max_total_commander_damage_dealt_lost INT
        , min_total_commander_damage_dealt_lost INT
        , total_commander_damage_received INT
        , mean_total_commander_damage_received FLOAT
        , max_total_commander_damage_received INT
        , min_total_commander_damage_received INT
        , total_commander_damage_received_game_won INT
        , mean_total_commander_damage_received_won FLOAT
        , max_total_commander_damage_received_won INT
        , min_total_commander_damage_received_won INT
        , total_commander_damage_received_game_lost INT
        , mean_total_commander_damage_received_lost FLOAT
        , max_total_commander_damage_received_lost INT
        , min_total_commander_damage_received_lost INT
        , total_life_gained INT
        , mean_total_life_gained FLOAT
        , max_total_life_gained INT
        , min_total_life_gained INT
        , total_life_gained_game_won INT
        , mean_total_life_gained_game_won FLOAT
        , max_total_life_gained_game_won INT
        , min_total_life_gained_game_won INT
        , total_life_gained_game_lost INT
        , mean_total_life_gained_game_lost FLOAT
        , max_total_life_gained_game_lost INT
        , min_total_life_gained_game_lost INT
        , total_game_round_count INT
        , mean_game_round_count FLOAT
        , lowest_game_round_count INT
        , highest_game_round_count INT
        , total_game_win_round_count INT
        , mean_game_win_round_count FLOAT
        , lowest_game_win_round_count INT
        , highest_game_win_round_count INT
        , total_game_lose_round_count INT
        , mean_game_lose_round_count FLOAT
        , lowest_game_lose_round_count INT
        , highest_game_lose_round_count INT
        , total_game_round_survived_count INT
        , mean_game_round_survived_count FLOAT
        , lowest_game_round_survived_count INT
        , highest_game_round_survived_count INT
        , total_game_win_round_survived_count INT
        , mean_game_win_round_survived_count FLOAT
        , lowest_game_win_round_survived_count INT
        , highest_game_win_round_survived_count INT
        , total_game_lose_round_survived_count INT
        , mean_game_lose_round_survived_count FLOAT
        , lowest_game_lose_round_survived_count INT
        , highest_game_lose_round_survived_count INT
        , total_game_duration INTERVAL
        , mean_game_duration INTERVAL
        , shortest_game_duration INTERVAL
        , longest_game_duration INTERVAL
        , total_game_win_duration INTERVAL
        , mean_game_win_duration INTERVAL
        , shortest_game_win_duration INTERVAL
        , longest_game_win_duration INTERVAL
        , total_game_lose_duration INTERVAL
        , mean_game_lose_duration INTERVAL
        , shortest_game_lose_duration INTERVAL
        , longest_game_lose_duration INTERVAL
        , total_commander_deaths INT
        , mean_commander_deaths FLOAT
        , max_commander_deaths INT
        , min_commander_deaths INT
        , total_commander_deaths_game_won INT
        , mean_commander_deaths_game_won FLOAT
        , max_commander_deaths_game_won INT
        , min_commander_deaths_game_won INT
        , total_commander_deaths_game_lost INT
        , mean_commander_deaths_game_lost FLOAT
        , max_commander_deaths_game_lost INT
        , min_commander_deaths_game_lost INT
        , total_pod_sizes INT
        , total_opponents_faced INT
        , mean_pod_size FLOAT
        , max_pod_size INT
        , min_pod_size INT
        , total_pod_sizes_won INT
        , total_opponents_beaten INT
        , mean_pod_size_won FLOAT
        , max_pod_size_won INT
        , min_pod_size_won INT
        , total_pod_sizes_lost INT
        , total_opponents_lost_to INT
        , mean_pod_size_lost FLOAT
        , max_pod_size_lost INT
        , min_pod_size_lost INT
        , latest_game_win_on TIMESTAMP
        , latest_game_win_pod_size INT
        , latest_game_lose_on TIMESTAMP
        , latest_game_lose_pod_size INT
        , archenemy_deck_id INT
        , rival_deck_id INT
        , archenemy_player_id INT
        , rival_player_id INT
        -- total starting life
        -- total different opponents, decks faced
    );

    CREATE TEMP TABLE Temp_Statistic_Calc_Round (
          round_id INT
        , game_id INT
        , notes TEXT
        , display_order INT
        , active BOOLEAN
        , created_on TIMESTAMP
        , created_by_user_id INT
        , updated_last_on TIMESTAMP
        , updated_last_by_user_id INT
		, change_set_id INT
    );

    CREATE TEMP TABLE Temp_Statistic_Calc_Round_Player_Damage (
          damage_id INT
        , temp_round_id INT
        , round_id INT
        , player_id INT
        , received_from_commander_player_id INT
        , life_gain INT
        , life_loss INT
        , commander_deaths INT
		, is_eliminated BOOLEAN
        , active BOOLEAN
        , created_on TIMESTAMP
        , created_by_user_id INT
        , updated_last_on TIMESTAMP
        , updated_last_by_user_id INT
		, change_set_id INT
    );

    CREATE TEMP TABLE Temp_Statistic_Calc_Player_Round_Link (
          game_id INT
        , player_id INT
        , round_id INT
        
        , is_eliminated BOOLEAN
        , max_total_commander_damage_received INT
        , total_commander_damage_dealt INT
        , total_damage_received INT
        , total_commander_deaths INT
        , total_life_gained INT
    );

	CREATE TEMP TABLE Temp_Statistic_Calc_Error (
		  temp_id INT GENERATED ALWAYS AS IDENTITY
		, error_type_id INT
		, message TEXT
	);

    IF NOT EXISTS (SELECT * FROM tcg.public.TCG_User TCG_USER WHERE TCG_USER.user_id = v_user_id LIMIT 1) THEN
        INSERT INTO Temp_Statistic_Calc_Error (
              error_type_id
            , message
        )
        VALUES (
              v_no_permission_error_type_id -- error_type_id
            , CONCAT(
                'User does not exist: '
                , CAST(v_user_id AS VARCHAR)
                , '.'
            ) -- message
        );
    END IF;

    IF v_user_id <> 3 THEN
        INSERT INTO Temp_Statistic_Calc_Error (
              error_type_id
            , message
        )
        VALUES (
              v_no_permission_error_type_id -- error_type_id
        	, 'No access.' -- message
        );
    END IF;
	
    INSERT INTO Temp_Statistic_Calc_Game (
          game_id
        , notes
        , is_commander
        , is_draft
        , is_sealed
        , location_name
        , start_on
        , end_on
        , starting_life
        , active
        , created_on
        , created_by_user_id
        , updated_last_on
        , updated_last_by_user_id
        , change_set_id
    )
	SELECT
		  GAME.game_id
        , GAME.notes
        , GAME.is_commander
        , GAME.is_draft
        , GAME.is_sealed
        , GAME.location_name
        , GAME.start_on
        , GAME.end_on
        , GAME.starting_life
        , GAME.active
        , GAME.created_on
        , GAME.created_by_user_id
        , GAME.updated_last_on
        , GAME.updated_last_by_user_id
        , GAME.change_set_id
	FROM tcg.public.TCG_MTG_Game GAME
	WHERE GAME.active
	;
	
	INSERT INTO Temp_Statistic_Calc_Round (
		  round_id
        , game_id
        , notes
        , display_order
        , active
        , created_on
        , created_by_user_id
        , updated_last_on
        , updated_last_by_user_id
        , change_set_id
	)
	SELECT
		  TCG_ROUND.round_id
        , TCG_ROUND.game_id
        , TCG_ROUND.notes
        , TCG_ROUND.display_order
        , TCG_ROUND.active
        , TCG_ROUND.created_on
        , TCG_ROUND.created_by_user_id
        , TCG_ROUND.updated_last_on
        , TCG_ROUND.updated_last_by_user_id
        , TCG_ROUND.change_set_id
	FROM tcg.public.TCG_MTG_Game_Round TCG_ROUND
	INNER JOIN Temp_Statistic_Calc_Game T_GAME ON TCG_ROUND.game_id = T_GAME.game_id
	WHERE TCG_ROUND.active
	;
	
	INSERT INTO Temp_Statistic_Calc_Player (
		  player_id
        , game_id
        , user_id
        , deck_id
        , name
        , notes
        , display_order
        , active
	)
	SELECT
		  PLAYER.player_id
        , PLAYER.game_id
        , PLAYER.user_id
        , PLAYER.deck_id
        , PLAYER.name
        , PLAYER.notes
        , PLAYER.display_order
        , PLAYER.active
	FROM tcg.public.TCG_MTG_Game_Player PLAYER
	INNER JOIN Temp_Statistic_Calc_Game T_GAME ON PLAYER.game_id = T_GAME.game_id
	INNER JOIN tcg.public.TCG_User TCG_USER
		ON 	PLAYER.user_id = TCG_USER.user_id
		AND TCG_USER.active
	WHERE PLAYER.active
	;
	
	INSERT INTO Temp_Statistic_Calc_Round_Player_Damage (
		  damage_id
        , round_id
        , player_id
        , received_from_commander_player_id
        , life_gain
        , life_loss
        , commander_deaths
		, is_eliminated
        , active
        , created_on
        , created_by_user_id
        , updated_last_on
        , updated_last_by_user_id
        , change_set_id
	)
	SELECT
		  PLAYER_DAMAGE.damage_id
        , PLAYER_DAMAGE.round_id
        , PLAYER_DAMAGE.player_id
        , PLAYER_DAMAGE.received_from_commander_player_id
        , PLAYER_DAMAGE.life_gain
        , PLAYER_DAMAGE.life_loss
        , PLAYER_DAMAGE.commander_deaths
		, PLAYER_DAMAGE.is_eliminated
        , PLAYER_DAMAGE.active
        , PLAYER_DAMAGE.created_on
        , PLAYER_DAMAGE.created_by_user_id
        , PLAYER_DAMAGE.updated_last_on
        , PLAYER_DAMAGE.updated_last_by_user_id
        , PLAYER_DAMAGE.change_set_id
	FROM tcg.public.TCG_MTG_Game_Round_Player_Damage PLAYER_DAMAGE
	INNER JOIN Temp_Statistic_Calc_Round T_ROUND ON PLAYER_DAMAGE.round_id = T_ROUND.round_id
	INNER JOIN Temp_Statistic_Calc_Player T_PLAYER ON PLAYER_DAMAGE.player_id = T_PLAYER.player_id
	WHERE PLAYER_DAMAGE.active
	;

    INSERT INTO Temp_Statistic_Calc_User (
          user_id
        , user_auth0_id
        , firstname
        , surname
        , email
        , is_email_verified
        , is_super_user
        , active
        , created_on
        , created_by_user_id
        , updated_last_on
        , updated_last_by_user_id
        , change_set_id
    )
    SELECT DISTINCT
          TCG_USER.user_id
        , TCG_USER.user_auth0_id
        , TCG_USER.firstname
        , TCG_USER.surname
        , TCG_USER.email
        , TCG_USER.is_email_verified
        , TCG_USER.is_super_user
        , TCG_USER.active
        , TCG_USER.created_on
        , TCG_USER.created_by_user_id
        , TCG_USER.updated_last_on
        , TCG_USER.updated_last_by_user_id
        , TCG_USER.change_set_id
    FROM tcg.public.TCG_User TCG_USER
    INNER JOIN Temp_Statistic_Calc_Player T_PLAYER ON TCG_USER.user_id = T_PLAYER.user_id
    ;

    INSERT INTO Temp_Statistic_Calc_Deck (
          deck_id
        , name
        , is_commander
        , commander_bracket_id
        , active
        , created_on
        , created_by_user_id
        , updated_last_on
        , updated_last_by_user_id
        , change_set_id
    )
    SELECT DISTINCT
          DECK.deck_id
        , DECK.name
        , DECK.is_commander
        , DECK.commander_bracket_id
        , DECK.active
        , DECK.created_on
        , DECK.created_by_user_id
        , DECK.updated_last_on
        , DECK.updated_last_by_user_id
        , DECK.change_set_id
    FROM tcg.public.TCG_MTG_Deck DECK
    INNER JOIN Temp_Statistic_Calc_Player T_PLAYER ON DECK.deck_id = T_PLAYER.deck_id
    WHERE DECK.active
    ;

    -- Statistics
    WITH
          Game_Length AS (
            SELECT
                  T_GAME.game_id
                , MAX(T_ROUND.display_order) AS max_round_display_order
            FROM Temp_Statistic_Calc_Game T_GAME
            INNER JOIN Temp_Statistic_Calc_Round T_ROUND
                ON  T_GAME.game_id = T_ROUND.game_id
                AND T_ROUND.active
            GROUP BY T_GAME.game_id
        )
        , Game_Size AS (
            SELECT
                  T_GAME.game_id
                , COUNT(*) AS count_players
            FROM Temp_Statistic_Calc_Game T_GAME
            INNER JOIN Temp_Statistic_Calc_Player T_PLAYER
                ON  T_GAME.game_id = T_PLAYER.game_id
                AND T_PLAYER.active
            GROUP BY T_GAME.game_id
        )
        , Game_Combined AS (
            SELECT
                  T_GAME.game_id
                , GAME_LENGTH.max_round_display_order
                , GAME_SIZE.count_players
            FROM Temp_Statistic_Calc_Game T_GAME
            LEFT JOIN Game_Length GAME_LENGTH ON T_GAME.game_id = GAME_LENGTH.game_id
            LEFT JOIN Game_Size GAME_SIZE ON T_GAME.game_id = GAME_SIZE.game_id
        )
    UPDATE Temp_Statistic_Calc_Game T_GAME
    SET
          max_round_display_order = COALESCE(GAME_COMBINED.max_round_display_order, 0)
        , count_players = COALESCE(GAME_COMBINED.count_players, 0)
        , duration = CASE
            WHEN
                    T_GAME.start_on IS NOT NULL
                AND T_GAME.end_on IS NOT NULL
            THEN T_GAME.end_on - T_GAME.start_on
            ELSE NULL
        END
    FROM Game_Combined GAME_COMBINED
    WHERE T_GAME.game_id = GAME_COMBINED.game_id
    ;

    WITH
          All_Player_Round AS (
            SELECT
                  T_ROUND.game_id
                , T_PLAYER.player_id
                , T_ROUND.round_id
            FROM Temp_Statistic_Calc_Round T_ROUND
            -- INNER JOIN Temp_Statistic_Calc_Game T_GAME ON T_ROUND.game_id = T_GAME.game_id
            INNER JOIN Temp_Statistic_Calc_Player T_PLAYER ON T_ROUND.game_id = T_PLAYER.game_id
        )
        , Player_Round_Commander_Damage_Received AS (
            SELECT
                  ALL_PLAYER_ROUND.game_id
                , ALL_PLAYER_ROUND.player_id
                , ALL_PLAYER_ROUND.round_id
        
                , SUM(T_PLAYER_DAMAGE.life_loss) AS total_commander_damage_received
            FROM All_Player_Round ALL_PLAYER_ROUND
            INNER JOIN Temp_Statistic_Calc_Round T_ROUND_PLAYER ON ALL_PLAYER_ROUND.round_id = T_ROUND_PLAYER.round_id
            INNER JOIN Temp_Statistic_Calc_Round T_ROUND_DAMAGE
                ON  T_ROUND_PLAYER.game_id = T_ROUND_DAMAGE.game_id
                AND T_ROUND_PLAYER.display_order >= T_ROUND_DAMAGE.display_order
            INNER JOIN Temp_Statistic_Calc_Round_Player_Damage T_PLAYER_DAMAGE
                ON  T_ROUND_DAMAGE.round_id = T_PLAYER_DAMAGE.round_id
                AND ALL_PLAYER_ROUND.player_id = T_PLAYER_DAMAGE.player_id
                AND T_PLAYER_DAMAGE.received_from_commander_player_id IS NOT NULL
            GROUP BY
                  ALL_PLAYER_ROUND.game_id
                , ALL_PLAYER_ROUND.player_id
                , ALL_PLAYER_ROUND.round_id
                -- , ALL_PLAYER_ROUND.received_from_commander_player_id
        )
        , Player_Round_Max_Commander_Damage_Received AS (
            SELECT
                  PLAYER_ROUND_COMMANDER_DAMAGE_IN.game_id
                , PLAYER_ROUND_COMMANDER_DAMAGE_IN.player_id
                , PLAYER_ROUND_COMMANDER_DAMAGE_IN.round_id
        
                , MAX(PLAYER_ROUND_COMMANDER_DAMAGE_IN.total_commander_damage_received) AS max_total_commander_damage_received
            FROM Player_Round_Commander_Damage_Received PLAYER_ROUND_COMMANDER_DAMAGE_IN
            GROUP BY
                  PLAYER_ROUND_COMMANDER_DAMAGE_IN.game_id
                , PLAYER_ROUND_COMMANDER_DAMAGE_IN.player_id
                , PLAYER_ROUND_COMMANDER_DAMAGE_IN.round_id
        )
        , Player_Round_Total_Commander_Damage_Dealt AS (
            SELECT
                  ALL_PLAYER_ROUND.game_id
                , ALL_PLAYER_ROUND.player_id
                , ALL_PLAYER_ROUND.round_id
        
                , SUM(T_PLAYER_DAMAGE.life_loss) AS total_commander_damage_dealt
            FROM All_Player_Round ALL_PLAYER_ROUND
            INNER JOIN Temp_Statistic_Calc_Round T_ROUND_PLAYER ON ALL_PLAYER_ROUND.round_id = T_ROUND_PLAYER.round_id
            INNER JOIN Temp_Statistic_Calc_Round T_ROUND_DAMAGE
                -- ON ALL_PLAYER_ROUND.round_id = T_ROUND_DAMAGE.round_id
                ON  T_ROUND_PLAYER.game_id = T_ROUND_DAMAGE.game_id
                AND T_ROUND_PLAYER.display_order >= T_ROUND_DAMAGE.display_order
            INNER JOIN Temp_Statistic_Calc_Round_Player_Damage T_PLAYER_DAMAGE
                ON  T_ROUND_DAMAGE.round_id = T_PLAYER_DAMAGE.round_id
                AND ALL_PLAYER_ROUND.player_id = T_PLAYER_DAMAGE.player_id
                AND T_PLAYER_DAMAGE.received_from_commander_player_id = ALL_PLAYER_ROUND.player_id
            GROUP BY
                  ALL_PLAYER_ROUND.game_id
                , ALL_PLAYER_ROUND.player_id
                , ALL_PLAYER_ROUND.round_id
        )
        , Player_Round_Damage AS (
            SELECT
                  ALL_PLAYER_ROUND.game_id
                , ALL_PLAYER_ROUND.player_id
                , ALL_PLAYER_ROUND.round_id
        
                , SUM(T_PLAYER_DAMAGE.life_loss) AS total_damage_received
            FROM All_Player_Round ALL_PLAYER_ROUND
            INNER JOIN Temp_Statistic_Calc_Round T_ROUND_PLAYER ON ALL_PLAYER_ROUND.round_id = T_ROUND_PLAYER.round_id
            INNER JOIN Temp_Statistic_Calc_Round T_ROUND_DAMAGE
                -- ON ALL_PLAYER_ROUND.round_id = T_ROUND_DAMAGE.round_id
                ON  T_ROUND_PLAYER.game_id = T_ROUND_DAMAGE.game_id
                AND T_ROUND_PLAYER.display_order >= T_ROUND_DAMAGE.display_order
            INNER JOIN Temp_Statistic_Calc_Round_Player_Damage T_PLAYER_DAMAGE
                ON  T_ROUND_DAMAGE.round_id = T_PLAYER_DAMAGE.round_id
                AND ALL_PLAYER_ROUND.player_id = T_PLAYER_DAMAGE.player_id
                AND T_PLAYER_DAMAGE.life_loss > 0
            GROUP BY
                  ALL_PLAYER_ROUND.game_id
                , ALL_PLAYER_ROUND.player_id
                , ALL_PLAYER_ROUND.round_id
        )
        , Player_Round_Eliminated AS (
            SELECT
                  ALL_PLAYER_ROUND.game_id
                , ALL_PLAYER_ROUND.player_id
                , ALL_PLAYER_ROUND.round_id
        
                , BOOL_OR(T_PLAYER_DAMAGE.is_eliminated) AS is_eliminated
                , SUM(T_PLAYER_DAMAGE.commander_deaths) AS total_commander_deaths
            FROM All_Player_Round ALL_PLAYER_ROUND
            INNER JOIN Temp_Statistic_Calc_Round T_ROUND_PLAYER ON ALL_PLAYER_ROUND.round_id = T_ROUND_PLAYER.round_id
            INNER JOIN Temp_Statistic_Calc_Round T_ROUND_DAMAGE
                ON  T_ROUND_PLAYER.game_id = T_ROUND_DAMAGE.game_id
                AND T_ROUND_PLAYER.display_order >= T_ROUND_DAMAGE.display_order
            INNER JOIN Temp_Statistic_Calc_Round_Player_Damage T_PLAYER_DAMAGE
                ON  T_ROUND_DAMAGE.round_id = T_PLAYER_DAMAGE.round_id
                AND ALL_PLAYER_ROUND.player_id = T_PLAYER_DAMAGE.player_id
            GROUP BY
                  ALL_PLAYER_ROUND.game_id
                , ALL_PLAYER_ROUND.player_id
                , ALL_PLAYER_ROUND.round_id
        )
        , Player_Round_Total_Life AS (
            SELECT
                  ALL_PLAYER_ROUND.game_id
                , ALL_PLAYER_ROUND.player_id
                , ALL_PLAYER_ROUND.round_id
        
                , SUM(T_PLAYER_DAMAGE.life_gain) AS total_life_gained
            FROM All_Player_Round ALL_PLAYER_ROUND
            INNER JOIN Temp_Statistic_Calc_Round T_ROUND_PLAYER ON ALL_PLAYER_ROUND.round_id = T_ROUND_PLAYER.round_id
            INNER JOIN Temp_Statistic_Calc_Round T_ROUND_DAMAGE
                -- ON ALL_PLAYER_ROUND.round_id = T_ROUND_DAMAGE.round_id
                ON  T_ROUND_PLAYER.game_id = T_ROUND_DAMAGE.game_id
                AND T_ROUND_PLAYER.display_order >= T_ROUND_DAMAGE.display_order
            INNER JOIN Temp_Statistic_Calc_Round_Player_Damage T_PLAYER_DAMAGE
                ON  T_ROUND_DAMAGE.round_id = T_PLAYER_DAMAGE.round_id
                AND ALL_PLAYER_ROUND.player_id = T_PLAYER_DAMAGE.player_id
                AND T_PLAYER_DAMAGE.life_gain > 0
            GROUP BY
                  ALL_PLAYER_ROUND.game_id
                , ALL_PLAYER_ROUND.player_id
                , ALL_PLAYER_ROUND.round_id
        )
    INSERT INTO Temp_Statistic_Calc_Player_Round_Link (
          game_id
        , player_id
        , round_id
        
        , max_total_commander_damage_received
        , total_commander_damage_dealt
        , total_damage_received
        , is_eliminated
        , total_commander_deaths
        , total_life_gained
    )
    SELECT
          ALL_PLAYER_ROUND.game_id
        , ALL_PLAYER_ROUND.player_id
        , ALL_PLAYER_ROUND.round_id

        , PLAYER_ROUND_MAX_CDR_DAMAGE_IN.max_total_commander_damage_received
        , PLAYER_ROUND_TOTAL_CDR_DAMAGE_OUT.total_commander_damage_dealt
        , PLAYER_ROUND_TOTAL_DAMAGE.total_damage_received
        , PLAYER_ROUND_ELIMINATED.is_eliminated
        , PLAYER_ROUND_ELIMINATED.total_commander_deaths
        , PLAYER_ROUND_TOTAL_LIFE.total_life_gained
    FROM All_Player_Round ALL_PLAYER_ROUND
    INNER JOIN Player_Round_Max_Commander_Damage_Received PLAYER_ROUND_MAX_CDR_DAMAGE_IN
        ON  ALL_PLAYER_ROUND.round_id = PLAYER_ROUND_MAX_CDR_DAMAGE_IN.round_id
        AND ALL_PLAYER_ROUND.player_id = PLAYER_ROUND_MAX_CDR_DAMAGE_IN.player_id
    INNER JOIN Player_Round_Total_Commander_Damage_Dealt PLAYER_ROUND_TOTAL_CDR_DAMAGE_OUT
        ON  ALL_PLAYER_ROUND.round_id = PLAYER_ROUND_TOTAL_CDR_DAMAGE_OUT.round_id
        AND ALL_PLAYER_ROUND.player_id = PLAYER_ROUND_TOTAL_CDR_DAMAGE_OUT.player_id
    INNER JOIN Player_Round_Damage PLAYER_ROUND_TOTAL_DAMAGE
        ON  ALL_PLAYER_ROUND.round_id = PLAYER_ROUND_TOTAL_DAMAGE.round_id
        AND ALL_PLAYER_ROUND.player_id = PLAYER_ROUND_TOTAL_DAMAGE.player_id
    INNER JOIN Player_Round_Eliminated PLAYER_ROUND_ELIMINATED
        ON  ALL_PLAYER_ROUND.round_id = PLAYER_ROUND_ELIMINATED.round_id
        AND ALL_PLAYER_ROUND.player_id = PLAYER_ROUND_ELIMINATED.player_id
    INNER JOIN Player_Round_Total_Life PLAYER_ROUND_TOTAL_LIFE
        ON  ALL_PLAYER_ROUND.round_id = PLAYER_ROUND_TOTAL_LIFE.round_id
        AND ALL_PLAYER_ROUND.player_id = PLAYER_ROUND_TOTAL_LIFE.player_id
    ;

    WITH
          Player_Round_Eliminated AS (
            SELECT
                  T_PLAYER_ROUND_LINK.player_id
                , T_GAME.game_id
                , T_GAME.max_round_display_order AS game_max_round_display_order
                , MIN(T_ROUND.display_order) AS round_display_order
            FROM Temp_Statistic_Calc_Player_Round_Link T_PLAYER_ROUND_LINK
            INNER JOIN Temp_Statistic_Calc_Round T_ROUND ON T_PLAYER_ROUND_LINK.round_id = T_ROUND.round_id
            INNER JOIN Temp_Statistic_Calc_Game T_GAME ON T_PLAYER_ROUND_LINK.game_id = T_GAME.game_id
            WHERE
                    T_PLAYER_ROUND_LINK.max_total_commander_damage_received >= v_commander_damage_limit
                OR  T_PLAYER_ROUND_LINK.total_damage_received - T_PLAYER_ROUND_LINK.total_life_gained >= T_GAME.starting_life
                OR  T_PLAYER_ROUND_LINK.is_eliminated
            GROUP BY
                  T_PLAYER_ROUND_LINK.player_id
                , T_GAME.game_id
                , T_GAME.max_round_display_order
        )
        , Player_Round_Final AS (
            SELECT
                  PLAYER_ROUND_ELIMINATED.player_id
                , PLAYER_ROUND_ELIMINATED.round_display_order AS round_display_order_eliminated
                , COALESCE(
                      PLAYER_ROUND_ELIMINATED.round_display_order
                    , PLAYER_ROUND_ELIMINATED.game_max_round_display_order
                ) AS final_player_damage_round_display_order
                , T_ROUND_FINAL.round_id AS final_player_damage_round_id
                , RANK() OVER (
                    PARTITION BY PLAYER_ROUND_ELIMINATED.game_id
                    ORDER BY COALESCE(
                          PLAYER_ROUND_ELIMINATED.round_display_order
                        , PLAYER_ROUND_ELIMINATED.game_max_round_display_order + 1
                    )
                ) AS placement
            FROM Player_Round_Eliminated PLAYER_ROUND_ELIMINATED
            INNER JOIN Temp_Statistic_Calc_Round T_ROUND_FINAL
                ON  COALESCE(
                      PLAYER_ROUND_ELIMINATED.round_display_order
                    , PLAYER_ROUND_ELIMINATED.game_max_round_display_order + 1
                ) = T_ROUND_FINAL.display_order
                AND PLAYER_ROUND_ELIMINATED.game_id = T_ROUND_FINAL.game_id
                AND T_ROUND_FINAL.active
        )
        /*
        , Player_Placement AS (
            SELECT
                  PLAYER_ROUND_ELIMINATED.player_id
                , PLAYER_ROUND_ELIMINATED.round_display_order_eliminated
                , PLAYER_ROUND_ELIMINATED.final_player_damage_round_id
                , RANK() OVER (
                    PARTITION BY PLAYER_ROUND_ELIMINATED.game_id
                    ORDER BY COALESCE(
                          PLAYER_ROUND_ELIMINATED.round_display_order
                        , PLAYER_ROUND_ELIMINATED.game_max_round_display_order + 1
                    )
                ) AS placement
            FROM Player_Round_Eliminated PLAYER_ROUND_ELIMINATED
        )
        */
        , Player_Final_Round_Aggregated AS (
            SELECT
                  PLAYER_ROUND_FINAL.player_id
                , MAX(T_PLAYER_ROUND_LINK.max_total_commander_damage_received) AS max_total_commander_damage_received
                , SUM(T_PLAYER_ROUND_LINK.total_commander_damage_dealt) AS total_commander_damage_dealt
                , SUM(T_PLAYER_ROUND_LINK.total_damage_received) AS total_damage_received
                , SUM(T_PLAYER_ROUND_LINK.total_commander_deaths) AS total_commander_deaths
                , SUM(T_PLAYER_ROUND_LINK.total_life_gained) AS total_life_gained
            FROM Player_Round_Final PLAYER_ROUND_FINAL -- Player_Round_Eliminated PLAYER_ROUND_ELIMINATED
            INNER JOIN Temp_Statistic_Calc_Round T_ROUND ON PLAYER_ROUND_FINAL.final_player_damage_round_id = T_ROUND.round_id
            INNER JOIN Temp_Statistic_Calc_Player_Round_Link T_PLAYER_ROUND_LINK 
                ON  PLAYER_ROUND_FINAL.player_id = T_PLAYER_ROUND_LINK.player_id
                AND PLAYER_ROUND_FINAL.final_player_damage_round_id = T_PLAYER_ROUND_LINK.round_id
            GROUP BY PLAYER_ROUND_FINAL.player_id
        )
    UPDATE Temp_Statistic_Calc_Player T_PLAYER
    SET
          round_display_order_eliminated = PLAYER_ROUND_FINAL.round_display_order_eliminated
        , final_player_damage_round_id = PLAYER_ROUND_FINAL.final_player_damage_round_id
        , placement = PLAYER_ROUND_FINAL.placement
        , max_total_commander_damage_received = PLAYER_FINAL_ROUND_AGGREGATED.max_total_commander_damage_received
        , total_commander_damage_dealt = PLAYER_FINAL_ROUND_AGGREGATED.total_commander_damage_dealt
        , total_damage_received = PLAYER_FINAL_ROUND_AGGREGATED.total_damage_received
        , total_life_gained = PLAYER_FINAL_ROUND_AGGREGATED.total_life_gained
    /*
    FROM Player_Placement PLAYER_PLACEMENT
    INNER JOIN Player_Final_Round_Aggregated PLAYER_FINAL_ROUND_AGGREGATED ON PLAYER_PLACEMENT.player_id = PLAYER_FINAL_ROUND_AGGREGATED.player_id
    WHERE T_PLAYER.player_id = PLAYER_PLACEMENT.player_id
    */
    FROM Player_Round_Final PLAYER_ROUND_FINAL
    INNER JOIN Player_Final_Round_Aggregated PLAYER_FINAL_ROUND_AGGREGATED ON PLAYER_ROUND_FINAL.player_id = PLAYER_FINAL_ROUND_AGGREGATED.player_id
    WHERE T_PLAYER.player_id = PLAYER_ROUND_FINAL.player_id
    ;

    WITH
          Unique_User_Deck_Link AS (
            SELECT DISTINCT
                  T_PLAYER.user_id
                , T_PLAYER.deck_id
            FROM Temp_Statistic_Calc_Player T_PLAYER
        )
        , User_Deck_Game_Aggregated_Raw AS (
            SELECT
                  USER_DECK_LINK.user_id
                , USER_DECK_LINK.deck_id
                , COUNT(*) AS count_games
                /*
                , SUM(USER_DECK_LINK.count_mulligans) AS count_mulligans
                , MAX(USER_DECK_LINK.count_mulligans) AS max_count_mulligans
                , MIN(USER_DECK_LINK.count_mulligans) AS min_count_mulligans
                */
                , SUM(T_PLAYER.round_display_order_eliminated) AS total_round_display_order_eliminated
                , MAX(T_PLAYER.round_display_order_eliminated) AS max_round_display_order_eliminated
                , MIN(T_PLAYER.round_display_order_eliminated) AS min_round_display_order_eliminated
                , MAX(T_PLAYER.placement) AS worst_position
                , MIN(T_PLAYER.placement) AS best_position
                , SUM(T_PLAYER.max_total_commander_damage_received) AS total_commander_damage_received
                , MAX(T_PLAYER.max_total_commander_damage_received) AS max_total_commander_damage_received
                , MIN(T_PLAYER.max_total_commander_damage_received) AS min_total_commander_damage_received
                , SUM(T_PLAYER.total_commander_damage_dealt) AS total_commander_damage_dealt
                , MAX(T_PLAYER.total_commander_damage_dealt) AS max_total_commander_damage_dealt
                , MIN(T_PLAYER.total_commander_damage_dealt) AS min_total_commander_damage_dealt
                , SUM(T_PLAYER.total_damage_received) AS total_damage_received
                , MAX(T_PLAYER.total_damage_received) AS max_total_damage_received
                , MIN(T_PLAYER.total_damage_received) AS min_total_damage_received
                , SUM(T_PLAYER.total_life_gained) AS total_life_gained
                , MAX(T_PLAYER.total_life_gained) AS max_total_life_gained
                , MIN(T_PLAYER.total_life_gained) AS min_total_life_gained
                , SUM(T_PLAYER.total_commander_deaths) AS total_commander_deaths
                , MAX(T_PLAYER.total_commander_deaths) AS max_total_commander_deaths
                , MIN(T_PLAYER.total_commander_deaths) AS min_total_commander_deaths
                , SUM(T_GAME.max_round_display_order) AS total_round_display_order
                , MAX(T_GAME.max_round_display_order) AS max_round_display_order
                , MIN(T_GAME.max_round_display_order) AS min_round_display_order
                , SUM(T_GAME.count_players) AS total_pod_sizes
                , SUM(T_GAME.count_players) - COUNT(*) AS total_opponents_faced
                , MAX(T_GAME.count_players) AS max_pod_size
                , MIN(T_GAME.count_players) AS min_pod_size
                , SUM(T_GAME.duration) AS total_game_duration
                , MAX(T_GAME.duration) AS longest_game_duration
                , MIN(T_GAME.duration) AS shortest_game_duration
            FROM Unique_User_Deck_Link USER_DECK_LINK
            INNER JOIN Temp_Statistic_Calc_Player T_PLAYER
                ON  USER_DECK_LINK.user_id = T_PLAYER.user_id
                AND USER_DECK_LINK.deck_id = T_PLAYER.deck_id
            INNER JOIN Temp_Statistic_Calc_Game T_GAME ON T_PLAYER.game_id = T_GAME.game_id
            GROUP BY
                  USER_DECK_LINK.user_id
                , USER_DECK_LINK.deck_id
        )
        , User_Deck_Game_Win_Aggregated AS (
            SELECT
                  USER_DECK_LINK.user_id
                , USER_DECK_LINK.deck_id
                , COUNT(*) AS count_games
                , SUM(T_PLAYER.round_display_order_eliminated) AS total_round_display_order_eliminated
                , MAX(T_PLAYER.round_display_order_eliminated) AS max_round_display_order_eliminated
                , MIN(T_PLAYER.round_display_order_eliminated) AS min_round_display_order_eliminated
                , MAX(T_PLAYER.placement) AS worst_position
                , MIN(T_PLAYER.placement) AS best_position
                , SUM(T_PLAYER.max_total_commander_damage_received) AS total_commander_damage_received
                , MAX(T_PLAYER.max_total_commander_damage_received) AS max_total_commander_damage_received
                , MIN(T_PLAYER.max_total_commander_damage_received) AS min_total_commander_damage_received
                , SUM(T_PLAYER.total_commander_damage_dealt) AS total_commander_damage_dealt
                , MAX(T_PLAYER.total_commander_damage_dealt) AS max_total_commander_damage_dealt
                , MIN(T_PLAYER.total_commander_damage_dealt) AS min_total_commander_damage_dealt
                , SUM(T_PLAYER.total_damage_received) AS total_damage_received
                , MAX(T_PLAYER.total_damage_received) AS max_total_damage_received
                , MIN(T_PLAYER.total_damage_received) AS min_total_damage_received
                , SUM(T_PLAYER.total_life_gained) AS total_life_gained
                , MAX(T_PLAYER.total_life_gained) AS max_total_life_gained
                , MIN(T_PLAYER.total_life_gained) AS min_total_life_gained
                , SUM(T_PLAYER.total_commander_deaths) AS total_commander_deaths
                , MAX(T_PLAYER.total_commander_deaths) AS max_total_commander_deaths
                , MIN(T_PLAYER.total_commander_deaths) AS min_total_commander_deaths
                , SUM(T_GAME.max_round_display_order) AS total_round_display_order
                , MAX(T_GAME.max_round_display_order) AS max_round_display_order
                , MIN(T_GAME.max_round_display_order) AS min_round_display_order
                , SUM(T_GAME.count_players) AS total_pod_sizes
                , SUM(T_GAME.count_players) - COUNT(*) AS total_opponents_faced
                , MAX(T_GAME.count_players) AS max_pod_size
                , MIN(T_GAME.count_players) AS min_pod_size
                , SUM(T_GAME.duration) AS total_game_duration
                , MAX(T_GAME.duration) AS longest_game_duration
                , MIN(T_GAME.duration) AS shortest_game_duration
            FROM Unique_User_Deck_Link USER_DECK_LINK
            INNER JOIN Temp_Statistic_Calc_Player T_PLAYER
                ON  USER_DECK_LINK.user_id = T_PLAYER.user_id
                AND USER_DECK_LINK.deck_id = T_PLAYER.deck_id
                AND T_PLAYER.placement = 1
            INNER JOIN Temp_Statistic_Calc_Game T_GAME ON T_PLAYER.game_id = T_GAME.game_id
            GROUP BY
                  USER_DECK_LINK.user_id
                , USER_DECK_LINK.deck_id
        )
        , User_Deck_Game_Lose_Aggregated AS (
            SELECT
                  USER_DECK_LINK.user_id
                , USER_DECK_LINK.deck_id
                , COUNT(*) AS count_games
                , SUM(T_PLAYER.round_display_order_eliminated) AS total_round_display_order_eliminated
                , MAX(T_PLAYER.round_display_order_eliminated) AS max_round_display_order_eliminated
                , MIN(T_PLAYER.round_display_order_eliminated) AS min_round_display_order_eliminated
                , MAX(T_PLAYER.placement) AS worst_position
                , MIN(T_PLAYER.placement) AS best_position
                , SUM(T_PLAYER.max_total_commander_damage_received) AS total_commander_damage_received
                , MAX(T_PLAYER.max_total_commander_damage_received) AS max_total_commander_damage_received
                , MIN(T_PLAYER.max_total_commander_damage_received) AS min_total_commander_damage_received
                , SUM(T_PLAYER.total_commander_damage_dealt) AS total_commander_damage_dealt
                , MAX(T_PLAYER.total_commander_damage_dealt) AS max_total_commander_damage_dealt
                , MIN(T_PLAYER.total_commander_damage_dealt) AS min_total_commander_damage_dealt
                , SUM(T_PLAYER.total_damage_received) AS total_damage_received
                , MAX(T_PLAYER.total_damage_received) AS max_total_damage_received
                , MIN(T_PLAYER.total_damage_received) AS min_total_damage_received
                , SUM(T_PLAYER.total_life_gained) AS total_life_gained
                , MAX(T_PLAYER.total_life_gained) AS max_total_life_gained
                , MIN(T_PLAYER.total_life_gained) AS min_total_life_gained
                , SUM(T_PLAYER.total_commander_deaths) AS total_commander_deaths
                , MAX(T_PLAYER.total_commander_deaths) AS max_total_commander_deaths
                , MIN(T_PLAYER.total_commander_deaths) AS min_total_commander_deaths
                , SUM(T_GAME.max_round_display_order) AS total_round_display_order
                , MAX(T_GAME.max_round_display_order) AS max_round_display_order
                , MIN(T_GAME.max_round_display_order) AS min_round_display_order
                , SUM(T_GAME.count_players) AS total_pod_sizes
                , SUM(T_GAME.count_players) - COUNT(*) AS total_opponents_faced
                , MAX(T_GAME.count_players) AS max_pod_size
                , MIN(T_GAME.count_players) AS min_pod_size
                , SUM(T_GAME.duration) AS total_game_duration
                , MAX(T_GAME.duration) AS longest_game_duration
                , MIN(T_GAME.duration) AS shortest_game_duration
            FROM Unique_User_Deck_Link USER_DECK_LINK
            INNER JOIN Temp_Statistic_Calc_Player T_PLAYER
                ON  USER_DECK_LINK.user_id = T_PLAYER.user_id
                AND USER_DECK_LINK.deck_id = T_PLAYER.deck_id
                AND T_PLAYER.placement > 1
            INNER JOIN Temp_Statistic_Calc_Game T_GAME ON T_PLAYER.game_id = T_GAME.game_id
            GROUP BY
                  USER_DECK_LINK.user_id
                , USER_DECK_LINK.deck_id
        )
        , Latest_User_Deck_Game_Win AS (
            SELECT
                  USER_DECK_LINK.user_id
                , USER_DECK_LINK.deck_id
                , T_GAME.count_players AS pod_size
                , COALESCE(
                      T_GAME.start_on
                    , T_GAME.created_on
                ) AS start_on
                , ROW_NUMBER() OVER (
                    PARTITION BY
                          USER_DECK_LINK.user_id
                        , USER_DECK_LINK.deck_id
                    ORDER BY COALESCE(
                          T_GAME.start_on
                        , T_GAME.created_on
                    ) DESC
                ) AS index_in_user_and_deck
            FROM Unique_User_Deck_Link USER_DECK_LINK
            INNER JOIN Temp_Statistic_Calc_Player T_PLAYER
                ON  USER_DECK_LINK.user_id = T_PLAYER.user_id
                AND USER_DECK_LINK.deck_id = T_PLAYER.deck_id
                AND T_PLAYER.placement = 1
            INNER JOIN Temp_Statistic_Calc_Game T_GAME ON T_PLAYER.game_id = T_GAME.game_id
        )
        , Latest_User_Deck_Game_Lose AS (
            SELECT
                  USER_DECK_LINK.user_id
                , USER_DECK_LINK.deck_id
                , T_GAME.count_players AS pod_size
                , COALESCE(
                      T_GAME.start_on
                    , T_GAME.created_on
                ) AS start_on
                , ROW_NUMBER() OVER (
                    PARTITION BY
                        USER_DECK_LINK.user_id
                        , USER_DECK_LINK.deck_id
                    ORDER BY COALESCE(
                          T_GAME.start_on
                        , T_GAME.created_on
                    ) DESC
                ) AS index_in_user_and_deck
                FROM Unique_User_Deck_Link USER_DECK_LINK
            INNER JOIN Temp_Statistic_Calc_Player T_PLAYER
                ON  USER_DECK_LINK.user_id = T_PLAYER.user_id
                AND USER_DECK_LINK.deck_id = T_PLAYER.deck_id
                AND T_PLAYER.placement > 1
            INNER JOIN Temp_Statistic_Calc_Game T_GAME ON T_PLAYER.game_id = T_GAME.game_id
        )
        /*
        , Rival_Player AS (
            SELECT
                  USER_DECK_LINK.user_id
                , USER_DECK_LINK.deck_id
                , T_PLAYER_OPPONENT.player_id AS opponent_player_id
                , T_PLAYER_OPPONENT.user_id AS opponent_user_id
                , T_PLAYER_OPPONENT.deck_id AS opponent_deck_id
            FROM Unique_User_Deck_Link USER_DECK_LINK
            INNER JOIN Temp_Statistic_Calc_Player T_PLAYER
                ON  USER_DECK_LINK.user_id = T_PLAYER.user_id
                AND USER_DECK_LINK.deck_id = T_PLAYER.deck_id
            INNER JOIN Temp_Statistic_Calc_Player T_PLAYER_OPPONENT
                ON  T_PLAYER.game_id = T_PLAYER_OPPONENT.game_id
                AND T_PLAYER.player_id <> T_PLAYER_OPPONENT.player_id
        )
        , Rival_User AS (
            SELECT
                  USER_DECK_LINK.user_id
                , USER_DECK_LINK.deck_id
                , RIVAL_PLAYER.opponent_user_id
                , COUNT(*) AS count_decks_faced
            FROM Unique_User_Deck_Link USER_DECK_LINK
            INNER JOIN Rival_Player RIVAL_PLAYER
                ON  USER_DECK_LINK.user_id = RIVAL_PLAYER.user_id
                AND USER_DECK_LINK.deck_id = RIVAL_PLAYER.deck_id
            GROUP BY
                  USER_DECK_LINK.user_id
                , USER_DECK_LINK.deck_id
                , RIVAL_PLAYER.opponent_user_id
            HAVING ROW_NUMBER() OVER (
                PARTITION BY
                      USER_DECK_LINK.user_id
                    , USER_DECK_LINK.deck_id
                    , RIVAL_PLAYER.opponent_user_id
                ORDER BY COUNT(*) DESC
            ) = 1
        )
        , Rival_Deck AS (
            SELECT
                  USER_DECK_LINK.user_id
                , USER_DECK_LINK.deck_id
                , ARCHENEMY_PLAYER.opponent_deck_id
                , SUM(ARCHENEMY_PLAYER.placement_difference) AS total_placement_difference
            FROM Unique_User_Deck_Link USER_DECK_LINK
            INNER JOIN Archenemy_Player ARCHENEMY_PLAYER
                ON  USER_DECK_LINK.user_id = ARCHENEMY_PLAYER.user_id
                AND USER_DECK_LINK.deck_id = ARCHENEMY_PLAYER.deck_id
            GROUP BY
                  USER_DECK_LINK.user_id
                , USER_DECK_LINK.deck_id
                , T_PLAYER_OPPONENT.deck_id AS opponent_deck_id
            HAVING ROW_NUMBER() OVER (
                PARTITION BY
                      USER_DECK_LINK.user_id
                    , USER_DECK_LINK.deck_id
                    , ARCHENEMY_PLAYER.opponent_deck_id
                ORDER BY SUM(ARCHENEMY_PLAYER.placement_difference) DESC
            ) = 1
        )
        , Archenemy_Player AS (
            SELECT
                  USER_DECK_LINK.user_id
                , USER_DECK_LINK.deck_id
                , T_PLAYER_OPPONENT.player_id AS opponent_player_id
                , T_PLAYER_OPPONENT.user_id AS opponent_user_id
                , T_PLAYER_OPPONENT.deck_id AS opponent_deck_id
                , T_PLAYER_OPPONENT.placement - T_PLAYER.placement AS placement_difference
            FROM Unique_User_Deck_Link USER_DECK_LINK
            INNER JOIN Temp_Statistic_Calc_Player T_PLAYER
                ON  USER_DECK_LINK.user_id = T_PLAYER.user_id
                AND USER_DECK_LINK.deck_id = T_PLAYER.deck_id
            INNER JOIN Temp_Statistic_Calc_Game T_GAME ON T_PLAYER.game_id = T_GAME.game_id
            INNER JOIN Temp_Statistic_Calc_Player T_PLAYER_OPPONENT
                ON  T_GAME.game_id = T_PLAYER_OPPONENT.game_id
                AND T_PLAYER.player_id <> T_PLAYER_OPPONENT.player_id
                AND T_PLAYER.placement > T_PLAYER_OPPONENT.placement
        )
        , Archenemy_User AS (
            SELECT
                  USER_DECK_LINK.user_id
                , USER_DECK_LINK.deck_id
                , ARCHENEMY_PLAYER.opponent_user_id
                , SUM(ARCHENEMY_PLAYER.placement_difference)
                , COUNT(*) AS count_decks_faced
            FROM Unique_User_Deck_Link USER_DECK_LINK
            INNER JOIN Archenemy_Player ARCHENEMY_PLAYER
                ON  USER_DECK_LINK.user_id = ARCHENEMY_PLAYER.user_id
                AND USER_DECK_LINK.deck_id = ARCHENEMY_PLAYER.deck_id
            GROUP BY
                  USER_DECK_LINK.user_id
                , USER_DECK_LINK.deck_id
                , ARCHENEMY_PLAYER.opponent_user_id
            HAVING ROW_NUMBER() OVER (
                PARTITION BY
                      USER_DECK_LINK.user_id
                    , USER_DECK_LINK.deck_id
                    , ARCHENEMY_PLAYER.opponent_user_id
                ORDER BY SUM(ARCHENEMY_PLAYER.placement_difference) DESC
            ) = 1
        )
        , Archenemy_User_Game AS (
            SELECT
                  USER_DECK_LINK.user_id
                , USER_DECK_LINK.deck_id
                , ARCHENEMY_USER.opponent_user_id
                , COUNT(*) AS count_games_faced
            FROM Unique_User_Deck_Link USER_DECK_LINK
            /*
            INNER JOIN Temp_Statistic_Calc_Player T_PLAYER
                ON  USER_DECK_LINK.user_id = T_PLAYER.user_id
                AND USER_DECK_LINK.deck_id = T_PLAYER.deck_id
            */
            INNER JOIN Archenemy_User ARCHENEMY_USER
                ON  USER_DECK_LINK.user_id = ARCHENEMY_USER.user_id
                AND USER_DECK_LINK.deck_id = ARCHENEMY_USER.deck_id
            INNER JOIN (
                SELECT DISTINCT T_PLAYER_OPPONENT.game_id
                FROM Temp_Statistic_Calc_Player T_PLAYER_OPPONENT
                -- INNER JOIN Temp_Statistic_Calc_Player T_PLAYER_OPPONENT ON T_PLAYER_OPPONENT.user_id = ARCHENEMY_USER.opponent_user_id
                WHERE T_PLAYER_OPPONENT.player_id = ARCHENEMY_USER.player_id
            ) T_GAME_UNIQUE ON
            GROUP BY
                  USER_DECK_LINK.user_id
                , USER_DECK_LINK.deck_id
                , ARCHENEMY_PLAYER.opponent_user_id
        )
        , Archenemy_Deck AS (
            SELECT
                  USER_DECK_LINK.user_id
                , USER_DECK_LINK.deck_id
                , ARCHENEMY_PLAYER.opponent_deck_id
                , SUM(ARCHENEMY_PLAYER.placement_difference)
            FROM Unique_User_Deck_Link USER_DECK_LINK
            INNER JOIN Archenemy_Player ARCHENEMY_PLAYER
                ON  USER_DECK_LINK.user_id = ARCHENEMY_PLAYER.user_id
                AND USER_DECK_LINK.deck_id = ARCHENEMY_PLAYER.deck_id
            GROUP BY
                  USER_DECK_LINK.user_id
                , USER_DECK_LINK.deck_id
                , T_PLAYER_OPPONENT.deck_id AS opponent_deck_id
            HAVING ROW_NUMBER() OVER (
                PARTITION BY
                      USER_DECK_LINK.user_id
                    , USER_DECK_LINK.deck_id
                    , ARCHENEMY_PLAYER.opponent_deck_id
                ORDER BY SUM(ARCHENEMY_PLAYER.placement_difference) DESC
            ) = 1
        )
        , Archenemy_Deck_Game AS (
            SELECT
                  USER_DECK_LINK.user_id
                , USER_DECK_LINK.deck_id
                , ARCHENEMY_PLAYER.opponent_user_id
                , COUNT(*) AS count_games_faced
            FROM Unique_User_Deck_Link USER_DECK_LINK
            INNER JOIN Archenemy_Deck ARCHENEMY_DECK
                ON  USER_DECK_LINK.user_id = ARCHENEMY_DECK.user_id
                AND USER_DECK_LINK.deck_id = ARCHENEMY_DECK.deck_id
            -- INNER JOIN Temp_Statistic_Calc_Player T_PLAYER_OPPONENT ON T_PLAYER_OPPONENT.user_id = ARCHENEMY_USER.opponent_user_id
            INNER JOIN Temp_Statistic_Calc_Game T_GAME ON T_GAME.game_id IN (
                SELECT DISTINCT T_PLAYER_OPPONENT.game_id
                FROM Temp_Statistic_Calc_Player T_PLAYER_OPPONENT
                WHERE T_PLAYER_OPPONENT.player_id = ARCHENEMY_PLAYER.player_id
            )
            GROUP BY
                  USER_DECK_LINK.user_id
                , USER_DECK_LINK.deck_id
                , ARCHENEMY_PLAYER.opponent_user_id
        )
        */
    INSERT INTO Temp_Statistic_Calc_User_Deck_Link (
          user_id
        , deck_id
        , count_games
        , count_games_won
        , count_games_lost
        , win_lose_ratio
        /*
        , mean_mulligan_count
        , max_mulligan_count
        , min_mulligan_count
        */
        , best_position
        , worst_position
        , total_damage_received
        , mean_total_damage_received
        , max_total_damage_received
        , min_total_damage_received
        , total_damage_received_game_win
        , mean_total_damage_received_game_win
        , max_total_damage_received_game_win
        , min_total_damage_received_game_win
        , total_damage_received_game_lose
        , mean_total_damage_received_game_lose
        , max_total_damage_received_game_lose
        , min_total_damage_received_game_lose
        , total_commander_damage_dealt
        , mean_total_commander_damage_dealt
        , max_total_commander_damage_dealt
        , min_total_commander_damage_dealt
        , total_commander_damage_dealt_game_won
        , mean_total_commander_damage_dealt_won
        , max_total_commander_damage_dealt_won
        , min_total_commander_damage_dealt_won
        , total_commander_damage_dealt_game_lost
        , mean_total_commander_damage_dealt_lost
        , max_total_commander_damage_dealt_lost
        , min_total_commander_damage_dealt_lost
        , total_commander_damage_received
        , mean_total_commander_damage_received
        , max_total_commander_damage_received
        , min_total_commander_damage_received
        , total_commander_damage_received_game_won
        , mean_total_commander_damage_received_won
        , max_total_commander_damage_received_won
        , min_total_commander_damage_received_won
        , total_commander_damage_received_game_lost
        , mean_total_commander_damage_received_lost
        , max_total_commander_damage_received_lost
        , min_total_commander_damage_received_lost
        , total_life_gained
        , mean_total_life_gained
        , max_total_life_gained
        , min_total_life_gained
        , total_life_gained_game_won
        , mean_total_life_gained_game_won
        , max_total_life_gained_game_won
        , min_total_life_gained_game_won
        , total_life_gained_game_lost
        , mean_total_life_gained_game_lost
        , max_total_life_gained_game_lost
        , min_total_life_gained_game_lost
        , total_game_round_count
        , mean_game_round_count
        , lowest_game_round_count
        , highest_game_round_count
        , total_game_win_round_count
        , mean_game_win_round_count
        , lowest_game_win_round_count
        , highest_game_win_round_count
        , total_game_lose_round_count
        , mean_game_lose_round_count
        , lowest_game_lose_round_count
        , highest_game_lose_round_count
        , total_game_round_survived_count
        , mean_game_round_survived_count
        , lowest_game_round_survived_count
        , highest_game_round_survived_count
        , total_game_win_round_survived_count
        , mean_game_win_round_survived_count
        , lowest_game_win_round_survived_count
        , highest_game_win_round_survived_count
        , total_game_lose_round_survived_count
        , mean_game_lose_round_survived_count
        , lowest_game_lose_round_survived_count
        , highest_game_lose_round_survived_count
        , total_game_duration
        , mean_game_duration
        , shortest_game_duration
        , longest_game_duration
        , total_game_win_duration
        , mean_game_win_duration
        , shortest_game_win_duration
        , longest_game_win_duration
        , total_game_lose_duration
        , mean_game_lose_duration
        , shortest_game_lose_duration
        , longest_game_lose_duration
        , total_commander_deaths
        , mean_commander_deaths
        , max_commander_deaths
        , min_commander_deaths
        , total_commander_deaths_game_won
        , mean_commander_deaths_game_won
        , max_commander_deaths_game_won
        , min_commander_deaths_game_won
        , total_commander_deaths_game_lost
        , mean_commander_deaths_game_lost
        , max_commander_deaths_game_lost
        , min_commander_deaths_game_lost
        , total_pod_sizes
        , total_opponents_faced
        , mean_pod_size
        , max_pod_size
        , min_pod_size
        , total_pod_sizes_won
        , total_opponents_beaten
        , mean_pod_size_won
        , max_pod_size_won
        , min_pod_size_won
        , total_pod_sizes_lost
        , total_opponents_lost_to
        , mean_pod_size_lost
        , max_pod_size_lost
        , min_pod_size_lost
        , latest_game_win_on
        , latest_game_win_pod_size
        , latest_game_lose_on
        , latest_game_lose_pod_size
        /*
        , archenemy_deck_id
        , rival_deck_id
        , archenemy_player_id
        , rival_player_id
        , count_games_against_self
        , count_players_against_self
        / *
        , colours faced
        , deck archetypes faced?
        */
    )
    SELECT
          USER_DECK_AGGREGATED_RAW.user_id
        , USER_DECK_AGGREGATED_RAW.deck_id
        , USER_DECK_AGGREGATED_RAW.count_games
        , USER_DECK_WIN_AGGREGATED_RAW.count_games -- count_games_won
        , USER_DECK_LOSE_AGGREGATED_RAW.count_games -- count_games_lost
        , CASE
            WHEN USER_DECK_LOSE_AGGREGATED_RAW.count_games > 0
                THEN USER_DECK_WIN_AGGREGATED_RAW.count_games / USER_DECK_LOSE_AGGREGATED_RAW.count_games
            ELSE COALESCE(USER_DECK_WIN_AGGREGATED_RAW.count_games, 0)
        END -- win_lose_ratio
        /*
        , mean_mulligan_count
        , max_mulligan_count
        , min_mulligan_count
        */
        , USER_DECK_AGGREGATED_RAW.best_position
        , USER_DECK_AGGREGATED_RAW.worst_position
        , USER_DECK_AGGREGATED_RAW.total_damage_received
        , CASE
            WHEN USER_DECK_AGGREGATED_RAW.count_games > 0
                THEN USER_DECK_AGGREGATED_RAW.total_damage_received / USER_DECK_AGGREGATED_RAW.count_games
            ELSE 0
        END -- mean_total_damage_received
        , USER_DECK_AGGREGATED_RAW.max_total_damage_received
        , USER_DECK_AGGREGATED_RAW.min_total_damage_received
        , USER_DECK_WIN_AGGREGATED_RAW.total_damage_received -- total_damage_received_game_win
        , CASE
            WHEN USER_DECK_WIN_AGGREGATED_RAW.count_games > 0
                THEN USER_DECK_WIN_AGGREGATED_RAW.total_damage_received / USER_DECK_WIN_AGGREGATED_RAW.count_games
            ELSE 0
        END -- mean_total_damage_received_game_win
        , USER_DECK_WIN_AGGREGATED_RAW.max_total_damage_received -- max_total_damage_received_game_win
        , USER_DECK_WIN_AGGREGATED_RAW.min_total_damage_received -- min_total_damage_received_game_win
        , USER_DECK_LOSE_AGGREGATED_RAW.total_damage_received -- total_damage_received_game_lose
        , CASE
            WHEN USER_DECK_LOSE_AGGREGATED_RAW.count_games > 0
                 THEN USER_DECK_LOSE_AGGREGATED_RAW.total_damage_received / USER_DECK_LOSE_AGGREGATED_RAW.count_games
            ELSE 0
        END -- mean_total_damage_received_game_lose
        , USER_DECK_LOSE_AGGREGATED_RAW.max_total_damage_received -- max_total_damage_received_game_lose
        , USER_DECK_LOSE_AGGREGATED_RAW.min_total_damage_received -- min_total_damage_received_game_lose
        , USER_DECK_AGGREGATED_RAW.total_commander_damage_dealt
        , CASE
            WHEN USER_DECK_AGGREGATED_RAW.count_games > 0
                THEN USER_DECK_AGGREGATED_RAW.total_commander_damage_dealt / USER_DECK_AGGREGATED_RAW.count_games
            ELSE 0
        END -- mean_total_commander_damage_dealt
        , USER_DECK_AGGREGATED_RAW.max_total_commander_damage_dealt
        , USER_DECK_AGGREGATED_RAW.min_total_commander_damage_dealt
        , USER_DECK_WIN_AGGREGATED_RAW.total_commander_damage_dealt -- total_commander_damage_dealt_game_won
        , CASE
            WHEN USER_DECK_WIN_AGGREGATED_RAW.count_games > 0
                THEN USER_DECK_WIN_AGGREGATED_RAW.total_commander_damage_dealt / USER_DECK_WIN_AGGREGATED_RAW.count_games
            ELSE 0
        END -- mean_total_commander_damage_dealt_won
        , USER_DECK_WIN_AGGREGATED_RAW.max_total_commander_damage_dealt -- max_total_commander_damage_dealt_won
        , USER_DECK_WIN_AGGREGATED_RAW.min_total_commander_damage_dealt -- min_total_commander_damage_dealt_won
        , USER_DECK_LOSE_AGGREGATED_RAW.total_commander_damage_dealt -- total_commander_damage_dealt_game_lost
        , CASE
            WHEN USER_DECK_LOSE_AGGREGATED_RAW.count_games > 0
                THEN USER_DECK_LOSE_AGGREGATED_RAW.total_commander_damage_dealt / USER_DECK_LOSE_AGGREGATED_RAW.count_games
            ELSE 0
        END -- mean_total_commander_damage_dealt_lost
        , USER_DECK_LOSE_AGGREGATED_RAW.max_total_commander_damage_dealt -- max_total_commander_damage_dealt_lost
        , USER_DECK_LOSE_AGGREGATED_RAW.min_total_commander_damage_dealt -- min_total_commander_damage_dealt_lost
        , USER_DECK_AGGREGATED_RAW.total_commander_damage_received
        , CASE
            WHEN USER_DECK_AGGREGATED_RAW.count_games > 0
                THEN USER_DECK_AGGREGATED_RAW.total_commander_damage_received / USER_DECK_AGGREGATED_RAW.count_games
            ELSE 0
        END -- mean_total_commander_damage_received
        , USER_DECK_AGGREGATED_RAW.max_total_commander_damage_received
        , USER_DECK_AGGREGATED_RAW.min_total_commander_damage_received
        , USER_DECK_WIN_AGGREGATED_RAW.total_commander_damage_received -- total_commander_damage_received_game_won
        , CASE
            WHEN USER_DECK_WIN_AGGREGATED_RAW.count_games > 0
                THEN USER_DECK_WIN_AGGREGATED_RAW.total_commander_damage_received / USER_DECK_WIN_AGGREGATED_RAW.count_games
            ELSE 0
        END -- mean_total_commander_damage_received_won
        , USER_DECK_WIN_AGGREGATED_RAW.max_total_commander_damage_received -- max_total_commander_damage_received_won
        , USER_DECK_WIN_AGGREGATED_RAW.min_total_commander_damage_received -- min_total_commander_damage_received_won
        , USER_DECK_LOSE_AGGREGATED_RAW.total_commander_damage_received -- total_commander_damage_received_game_lost
        , CASE
            WHEN USER_DECK_LOSE_AGGREGATED_RAW.count_games > 0
                THEN USER_DECK_LOSE_AGGREGATED_RAW.total_commander_damage_received / USER_DECK_LOSE_AGGREGATED_RAW.count_games
            ELSE 0
        END -- mean_total_commander_damage_received_lost
        , USER_DECK_LOSE_AGGREGATED_RAW.max_total_commander_damage_received -- max_total_commander_damage_received_lost
        , USER_DECK_LOSE_AGGREGATED_RAW.min_total_commander_damage_received -- min_total_commander_damage_received_lost
        , USER_DECK_AGGREGATED_RAW.total_life_gained
        , CASE
            WHEN USER_DECK_AGGREGATED_RAW.count_games > 0
                THEN USER_DECK_AGGREGATED_RAW.total_life_gained / USER_DECK_AGGREGATED_RAW.count_games
            ELSE 0
        END -- mean_total_life_gained
        , USER_DECK_AGGREGATED_RAW.max_total_life_gained
        , USER_DECK_AGGREGATED_RAW.min_total_life_gained
        , USER_DECK_WIN_AGGREGATED_RAW.total_life_gained -- total_life_gained_game_won
        , CASE
            WHEN USER_DECK_WIN_AGGREGATED_RAW.count_games > 0
                THEN USER_DECK_WIN_AGGREGATED_RAW.total_life_gained / USER_DECK_WIN_AGGREGATED_RAW.count_games
            ELSE 0
        END -- mean_total_life_gained_game_won
        , USER_DECK_WIN_AGGREGATED_RAW.max_total_life_gained -- max_total_life_gained_game_won
        , USER_DECK_WIN_AGGREGATED_RAW.min_total_life_gained -- min_total_life_gained_game_won
        , USER_DECK_LOSE_AGGREGATED_RAW.total_life_gained -- total_life_gained_game_lost
        , CASE
            WHEN USER_DECK_LOSE_AGGREGATED_RAW.count_games > 0
                THEN USER_DECK_LOSE_AGGREGATED_RAW.total_life_gained / USER_DECK_LOSE_AGGREGATED_RAW.count_games
            ELSE 0
        END -- mean_total_life_gained_game_lost
        , USER_DECK_LOSE_AGGREGATED_RAW.max_total_life_gained -- max_total_life_gained_game_lost
        , USER_DECK_LOSE_AGGREGATED_RAW.min_total_life_gained -- min_total_life_gained_game_lost
        , USER_DECK_AGGREGATED_RAW.total_round_display_order
        , CASE
            WHEN USER_DECK_AGGREGATED_RAW.count_games > 0
                THEN USER_DECK_AGGREGATED_RAW.total_round_display_order / USER_DECK_AGGREGATED_RAW.count_games
            ELSE 0
        END -- mean_game_round_count
        , USER_DECK_AGGREGATED_RAW.min_round_display_order -- lowest_game_round_count
        , USER_DECK_AGGREGATED_RAW.max_round_display_order -- highest_game_round_count
        , COALESCE(USER_DECK_WIN_AGGREGATED_RAW.total_round_display_order, 0) -- total_game_win_round_count
        , CASE
            WHEN USER_DECK_WIN_AGGREGATED_RAW.count_games > 0
                THEN USER_DECK_WIN_AGGREGATED_RAW.total_round_display_order / USER_DECK_WIN_AGGREGATED_RAW.count_games
            ELSE 0
        END -- mean_game_win_round_count
        , COALESCE(USER_DECK_WIN_AGGREGATED_RAW.min_round_display_order, 0) -- lowest_game_win_round_count
        , COALESCE(USER_DECK_WIN_AGGREGATED_RAW.max_round_display_order, 0) -- highest_game_win_round_count
        , USER_DECK_LOSE_AGGREGATED_RAW.total_round_display_order -- total_game_lose_round_count
        , CASE
            WHEN USER_DECK_LOSE_AGGREGATED_RAW.count_games > 0
                THEN USER_DECK_LOSE_AGGREGATED_RAW.total_round_display_order / USER_DECK_LOSE_AGGREGATED_RAW.count_games
            ELSE 0
        END -- mean_game_lose_round_count
        , COALESCE(USER_DECK_LOSE_AGGREGATED_RAW.min_round_display_order, 0) -- lowest_game_lose_round_count
        , COALESCE(USER_DECK_LOSE_AGGREGATED_RAW.max_round_display_order, 0) -- highest_game_lose_round_count
        , USER_DECK_AGGREGATED_RAW.total_round_display_order_eliminated -- total_game_round_survived_count
        , CASE
            WHEN USER_DECK_AGGREGATED_RAW.count_games > 0
                THEN USER_DECK_AGGREGATED_RAW.total_round_display_order_eliminated / USER_DECK_AGGREGATED_RAW.count_games
            ELSE 0
        END -- mean_game_round_survived_count
        , USER_DECK_AGGREGATED_RAW.min_round_display_order_eliminated -- lowest_game_round_survived_count
        , USER_DECK_AGGREGATED_RAW.max_round_display_order_eliminated -- highest_game_round_survived_count
        , USER_DECK_WIN_AGGREGATED_RAW.total_round_display_order_eliminated -- total_game_win_round_survived_count
        , CASE
            WHEN USER_DECK_WIN_AGGREGATED_RAW.count_games > 0
                THEN USER_DECK_WIN_AGGREGATED_RAW.total_round_display_order_eliminated / USER_DECK_WIN_AGGREGATED_RAW.count_games
            ELSE 0
        END -- mean_game_win_round_survived_count
        , USER_DECK_WIN_AGGREGATED_RAW.min_round_display_order_eliminated -- lowest_game_win_round_survived_count
        , USER_DECK_WIN_AGGREGATED_RAW.max_round_display_order_eliminated -- highest_game_win_round_survived_count
        , USER_DECK_LOSE_AGGREGATED_RAW.total_round_display_order_eliminated -- total_game_lose_round_survived_count
        , CASE
            WHEN USER_DECK_LOSE_AGGREGATED_RAW.count_games > 0
                THEN USER_DECK_LOSE_AGGREGATED_RAW.total_round_display_order_eliminated / USER_DECK_LOSE_AGGREGATED_RAW.count_games
            ELSE 0
        END -- mean_game_lose_round_survived_count
        , USER_DECK_LOSE_AGGREGATED_RAW.min_round_display_order_eliminated -- lowest_game_lose_round_survived_count
        , USER_DECK_LOSE_AGGREGATED_RAW.max_round_display_order_eliminated -- highest_game_lose_round_survived_count
        , USER_DECK_AGGREGATED_RAW.total_game_duration
        , CASE
            WHEN USER_DECK_AGGREGATED_RAW.count_games > 0
                THEN USER_DECK_AGGREGATED_RAW.total_game_duration / USER_DECK_AGGREGATED_RAW.count_games
            ELSE INTERVAL '0'
        END -- mean_game_duration
        , USER_DECK_AGGREGATED_RAW.shortest_game_duration
        , USER_DECK_AGGREGATED_RAW.longest_game_duration
        , USER_DECK_WIN_AGGREGATED_RAW.total_game_duration -- total_game_win_duration
        , CASE
            WHEN USER_DECK_WIN_AGGREGATED_RAW.count_games > 0
                THEN USER_DECK_WIN_AGGREGATED_RAW.total_game_duration / USER_DECK_WIN_AGGREGATED_RAW.count_games
            ELSE INTERVAL '0'
        END -- mean_game_win_duration
        , USER_DECK_WIN_AGGREGATED_RAW.shortest_game_duration -- shortest_game_win_duration
        , USER_DECK_WIN_AGGREGATED_RAW.longest_game_duration -- longest_game_win_duration
        , USER_DECK_LOSE_AGGREGATED_RAW.total_game_duration -- total_game_lose_duration
        , CASE
            WHEN USER_DECK_LOSE_AGGREGATED_RAW.count_games > 0
                THEN USER_DECK_LOSE_AGGREGATED_RAW.total_game_duration / USER_DECK_LOSE_AGGREGATED_RAW.count_games
            ELSE INTERVAL '0'
        END -- mean_game_lose_duration
        , USER_DECK_LOSE_AGGREGATED_RAW.shortest_game_duration -- shortest_game_lose_duration
        , USER_DECK_LOSE_AGGREGATED_RAW.longest_game_duration -- longest_game_lose_duration
        , USER_DECK_AGGREGATED_RAW.total_commander_deaths
        , CASE
            WHEN USER_DECK_AGGREGATED_RAW.count_games > 0
                THEN USER_DECK_AGGREGATED_RAW.total_commander_deaths / USER_DECK_AGGREGATED_RAW.count_games
            ELSE 0
        END -- mean_commander_deaths
        , USER_DECK_AGGREGATED_RAW.max_total_commander_deaths -- max_commander_deaths
        , USER_DECK_AGGREGATED_RAW.min_total_commander_deaths -- min_commander_deaths
        , USER_DECK_WIN_AGGREGATED_RAW.total_commander_deaths -- total_commander_deaths_game_won
        , CASE
            WHEN USER_DECK_WIN_AGGREGATED_RAW.count_games > 0
                THEN USER_DECK_WIN_AGGREGATED_RAW.total_commander_deaths / USER_DECK_WIN_AGGREGATED_RAW.count_games
            ELSE 0
        END -- mean_commander_deaths_game_won
        , USER_DECK_WIN_AGGREGATED_RAW.max_total_commander_deaths -- max_commander_deaths_game_won
        , USER_DECK_WIN_AGGREGATED_RAW.min_total_commander_deaths -- min_commander_deaths_game_won
        , USER_DECK_LOSE_AGGREGATED_RAW.total_commander_deaths -- total_commander_deaths_game_lost
        , CASE
            WHEN USER_DECK_LOSE_AGGREGATED_RAW.count_games > 0
                THEN USER_DECK_LOSE_AGGREGATED_RAW.total_commander_deaths / USER_DECK_LOSE_AGGREGATED_RAW.count_games
            ELSE 0
        END -- mean_commander_deaths_game_lost
        , USER_DECK_LOSE_AGGREGATED_RAW.max_total_commander_deaths -- max_commander_deaths_game_lost
        , USER_DECK_LOSE_AGGREGATED_RAW.min_total_commander_deaths -- min_commander_deaths_game_lost
        , USER_DECK_AGGREGATED_RAW.total_pod_sizes
        , USER_DECK_AGGREGATED_RAW.total_opponents_faced
        , CASE
            WHEN USER_DECK_AGGREGATED_RAW.count_games > 0
                THEN USER_DECK_AGGREGATED_RAW.total_pod_sizes / USER_DECK_AGGREGATED_RAW.count_games
            ELSE 0
        END -- mean_pod_size
        , USER_DECK_AGGREGATED_RAW.max_pod_size
        , USER_DECK_AGGREGATED_RAW.min_pod_size
        , USER_DECK_WIN_AGGREGATED_RAW.total_pod_sizes -- total_pod_sizes_won
        , USER_DECK_WIN_AGGREGATED_RAW.total_opponents_faced -- total_opponents_beaten
        , CASE
            WHEN USER_DECK_WIN_AGGREGATED_RAW.count_games > 0
                THEN USER_DECK_WIN_AGGREGATED_RAW.total_pod_sizes / USER_DECK_WIN_AGGREGATED_RAW.count_games
            ELSE 0
        END -- mean_pod_size_won
        , USER_DECK_WIN_AGGREGATED_RAW.max_pod_size -- max_pod_size_won
        , USER_DECK_WIN_AGGREGATED_RAW.min_pod_size -- min_pod_size_won
        , USER_DECK_LOSE_AGGREGATED_RAW.total_pod_sizes -- total_pod_sizes_lost
        , USER_DECK_LOSE_AGGREGATED_RAW.total_opponents_faced -- total_opponents_lost_to
        , CASE
            WHEN USER_DECK_LOSE_AGGREGATED_RAW.count_games > 0
                THEN USER_DECK_LOSE_AGGREGATED_RAW.total_pod_sizes / USER_DECK_LOSE_AGGREGATED_RAW.count_games
            ELSE 0
        END -- mean_pod_size_lost
        , USER_DECK_LOSE_AGGREGATED_RAW.max_pod_size -- max_pod_size_lost
        , USER_DECK_LOSE_AGGREGATED_RAW.min_pod_size -- min_pod_size_lost
        , LATEST_USER_DECK_WIN.start_on -- latest_game_win_on
        , LATEST_USER_DECK_WIN.pod_size -- latest_game_win_pod_size
        , LATEST_USER_DECK_LOSE.start_on -- latest_game_lose_on
        , LATEST_USER_DECK_LOSE.pod_size -- latest_game_lose_pod_size
        /*
        , archenemy_deck_id -- !!!
        , rival_deck_id -- !!!
        , archenemy_player_id -- !!!
        , rival_player_id -- !!!
        */
    FROM User_Deck_Game_Aggregated_Raw USER_DECK_AGGREGATED_RAW -- Unique_User_Deck_Link UNIQUE_USER_DECK_LINK
    LEFT JOIN User_Deck_Game_Win_Aggregated USER_DECK_WIN_AGGREGATED_RAW
        ON  USER_DECK_AGGREGATED_RAW.user_id = USER_DECK_WIN_AGGREGATED_RAW.user_id
        AND USER_DECK_AGGREGATED_RAW.deck_id = USER_DECK_WIN_AGGREGATED_RAW.deck_id
    LEFT JOIN User_Deck_Game_Lose_Aggregated USER_DECK_LOSE_AGGREGATED_RAW
        ON  USER_DECK_AGGREGATED_RAW.user_id = USER_DECK_LOSE_AGGREGATED_RAW.user_id
        AND USER_DECK_AGGREGATED_RAW.deck_id = USER_DECK_LOSE_AGGREGATED_RAW.deck_id
    LEFT JOIN Latest_User_Deck_Game_Win LATEST_USER_DECK_WIN
        ON  USER_DECK_AGGREGATED_RAW.user_id = LATEST_USER_DECK_WIN.user_id
        AND USER_DECK_AGGREGATED_RAW.deck_id = LATEST_USER_DECK_WIN.deck_id
        AND LATEST_USER_DECK_WIN.index_in_user_and_deck = 1
    LEFT JOIN Latest_User_Deck_Game_Lose LATEST_USER_DECK_LOSE
        ON  USER_DECK_AGGREGATED_RAW.user_id = LATEST_USER_DECK_LOSE.user_id
        AND USER_DECK_AGGREGATED_RAW.deck_id = LATEST_USER_DECK_LOSE.deck_id
        AND LATEST_USER_DECK_LOSE.index_in_user_and_deck = 1
    ;
    
    WITH
          Latest_User_Win AS (
            SELECT
                  T_USER_DECK_LINK.user_id
                , T_USER_DECK_LINK.latest_game_win_pod_size
                , T_USER_DECK_LINK.latest_game_win_on
                , ROW_NUMBER() OVER (
                    PARTITION BY T_USER_DECK_LINK.user_id
                    ORDER BY T_USER_DECK_LINK.latest_game_win_on DESC
                ) AS index_win_in_user
            FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
            GROUP BY
                  T_USER_DECK_LINK.user_id
                , T_USER_DECK_LINK.latest_game_win_pod_size
                , T_USER_DECK_LINK.latest_game_win_on
        )
        , Latest_User_Lose AS (
            SELECT
                  T_USER_DECK_LINK.user_id
                , T_USER_DECK_LINK.latest_game_lose_pod_size
                , T_USER_DECK_LINK.latest_game_lose_on
                , ROW_NUMBER() OVER (
                    PARTITION BY T_USER_DECK_LINK.user_id
                    ORDER BY T_USER_DECK_LINK.latest_game_lose_on DESC
                ) AS index_lose_in_user
            FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
            GROUP BY
                  T_USER_DECK_LINK.user_id
                , T_USER_DECK_LINK.latest_game_lose_pod_size
                , T_USER_DECK_LINK.latest_game_lose_on
        )
        , User_Summary AS (
            SELECT
                  T_USER_DECK_LINK.user_id
                , SUM(T_USER_DECK_LINK.count_games) AS count_games
                , SUM(T_USER_DECK_LINK.count_games_won) AS count_games_won
                , SUM(T_USER_DECK_LINK.count_games_lost) AS count_games_lost
                , CASE
                    WHEN SUM(T_USER_DECK_LINK.count_games_lost) > 0
                        THEN SUM(T_USER_DECK_LINK.count_games_won) / SUM(T_USER_DECK_LINK.count_games_lost)
                    ELSE COALESCE(SUM(T_USER_DECK_LINK.count_games_won), 0)
                END AS win_lose_ratio
                , MIN(T_USER_DECK_LINK.best_position) AS best_position
                , MAX(T_USER_DECK_LINK.worst_position) AS worst_position
                , SUM(T_USER_DECK_LINK.total_damage_received) AS total_damage_received
                , CASE
                    WHEN SUM(T_USER_DECK_LINK.count_games) > 0
                        THEN SUM(T_USER_DECK_LINK.total_damage_received) / SUM(T_USER_DECK_LINK.count_games)
                    ELSE 0
                END AS mean_total_damage_received
                , MAX(T_USER_DECK_LINK.max_total_damage_received) AS max_total_damage_received
                , MIN(T_USER_DECK_LINK.min_total_damage_received) AS min_total_damage_received
                , SUM(T_USER_DECK_LINK.total_damage_received_game_win) AS total_damage_received_game_win
                , CASE
                    WHEN SUM(T_USER_DECK_LINK.count_games_won) > 0
                        THEN SUM(T_USER_DECK_LINK.total_damage_received_game_win) / SUM(T_USER_DECK_LINK.count_games_won)
                    ELSE 0
                END AS mean_total_damage_received_game_win
                , MAX(T_USER_DECK_LINK.max_total_damage_received_game_win) AS max_total_damage_received_game_win
                , MIN(T_USER_DECK_LINK.min_total_damage_received_game_win) AS min_total_damage_received_game_win
                , SUM(T_USER_DECK_LINK.total_damage_received_game_lose) AS total_damage_received_game_lose
                , CASE
                    WHEN SUM(T_USER_DECK_LINK.count_games_lost) > 0
                        THEN SUM(T_USER_DECK_LINK.total_damage_received_game_lose) / SUM(T_USER_DECK_LINK.count_games_lost)
                    ELSE 0
                END AS mean_total_damage_received_game_lose
                , MAX(T_USER_DECK_LINK.max_total_damage_received_game_lose) AS max_total_damage_received_game_lose
                , MIN(T_USER_DECK_LINK.min_total_damage_received_game_lose) AS min_total_damage_received_game_lose
                , SUM(T_USER_DECK_LINK.total_commander_damage_dealt) AS total_commander_damage_dealt
                , CASE
                    WHEN SUM(T_USER_DECK_LINK.count_games) > 0
                        THEN SUM(T_USER_DECK_LINK.total_commander_damage_dealt) / SUM(T_USER_DECK_LINK.count_games)
                    ELSE 0
                END AS mean_total_commander_damage_dealt
                , MAX(T_USER_DECK_LINK.max_total_commander_damage_dealt) AS max_total_commander_damage_dealt
                , MIN(T_USER_DECK_LINK.min_total_commander_damage_dealt) AS min_total_commander_damage_dealt
                , SUM(T_USER_DECK_LINK.total_commander_damage_dealt_game_won) AS total_commander_damage_dealt_game_won
                , CASE
                    WHEN SUM(T_USER_DECK_LINK.count_games_won) > 0
                        THEN SUM(T_USER_DECK_LINK.total_commander_damage_dealt_game_won) / SUM(T_USER_DECK_LINK.count_games_won)
                    ELSE 0
                END AS mean_total_commander_damage_dealt_won
                , MAX(T_USER_DECK_LINK.max_total_commander_damage_dealt_won) AS max_total_commander_damage_dealt_won
                , MIN(T_USER_DECK_LINK.min_total_commander_damage_dealt_won) AS min_total_commander_damage_dealt_won
                , SUM(T_USER_DECK_LINK.total_commander_damage_dealt_game_lost) AS total_commander_damage_dealt_game_lost
                , CASE
                    WHEN SUM(T_USER_DECK_LINK.count_games_lost) > 0
                        THEN SUM(T_USER_DECK_LINK.total_commander_damage_dealt_game_lost) / SUM(T_USER_DECK_LINK.count_games_lost)
                    ELSE 0
                END AS mean_total_commander_damage_dealt_lost
                , MAX(T_USER_DECK_LINK.max_total_commander_damage_dealt_lost) AS max_total_commander_damage_dealt_lost
                , MIN(T_USER_DECK_LINK.min_total_commander_damage_dealt_lost) AS min_total_commander_damage_dealt_lost
                , SUM(T_USER_DECK_LINK.total_commander_damage_received) AS total_commander_damage_received
                , CASE
                    WHEN SUM(T_USER_DECK_LINK.count_games) > 0
                        THEN SUM(T_USER_DECK_LINK.total_commander_damage_received) / SUM(T_USER_DECK_LINK.count_games)
                    ELSE 0
                END AS mean_total_commander_damage_received
                , MAX(T_USER_DECK_LINK.max_total_commander_damage_received) AS max_total_commander_damage_received
                , MIN(T_USER_DECK_LINK.min_total_commander_damage_received) AS min_total_commander_damage_received
                , SUM(T_USER_DECK_LINK.total_commander_damage_received_game_won) AS total_commander_damage_received_game_won
                , CASE
                    WHEN SUM(T_USER_DECK_LINK.count_games_won) > 0
                        THEN SUM(T_USER_DECK_LINK.total_commander_damage_received_game_won) / SUM(T_USER_DECK_LINK.count_games_won)
                    ELSE 0
                END AS mean_total_commander_damage_received_won
                , MAX(T_USER_DECK_LINK.max_total_commander_damage_received_won) AS max_total_commander_damage_received_won
                , MIN(T_USER_DECK_LINK.min_total_commander_damage_received_won) AS min_total_commander_damage_received_won
                , SUM(T_USER_DECK_LINK.total_commander_damage_received_game_lost) AS total_commander_damage_received_game_lost
                , CASE
                    WHEN SUM(T_USER_DECK_LINK.count_games_lost) > 0
                        THEN SUM(T_USER_DECK_LINK.total_commander_damage_received_game_lost) / SUM(T_USER_DECK_LINK.count_games_lost)
                    ELSE 0
                END AS mean_total_commander_damage_received_lost
                , MAX(T_USER_DECK_LINK.max_total_commander_damage_received_lost) AS max_total_commander_damage_received_lost
                , MIN(T_USER_DECK_LINK.min_total_commander_damage_received_lost) AS min_total_commander_damage_received_lost
                , SUM(T_USER_DECK_LINK.total_life_gained) AS total_life_gained
                , CASE
                    WHEN SUM(T_USER_DECK_LINK.count_games) > 0
                        THEN SUM(T_USER_DECK_LINK.total_life_gained) / SUM(T_USER_DECK_LINK.count_games)
                    ELSE 0
                END AS mean_total_life_gained
                , MAX(T_USER_DECK_LINK.max_total_life_gained) AS max_total_life_gained
                , MIN(T_USER_DECK_LINK.min_total_life_gained) AS min_total_life_gained
                , SUM(T_USER_DECK_LINK.total_life_gained_game_won) AS total_life_gained_game_won
                , CASE
                    WHEN SUM(T_USER_DECK_LINK.count_games_won) > 0
                        THEN SUM(T_USER_DECK_LINK.total_life_gained_game_won) / SUM(T_USER_DECK_LINK.count_games_won)
                    ELSE 0
                END AS mean_total_life_gained_game_won
                , MAX(T_USER_DECK_LINK.max_total_life_gained_game_won) AS max_total_life_gained_game_won
                , MIN(T_USER_DECK_LINK.min_total_life_gained_game_won) AS min_total_life_gained_game_won
                , SUM(T_USER_DECK_LINK.total_life_gained_game_lost) AS total_life_gained_game_lost
                , CASE
                    WHEN SUM(T_USER_DECK_LINK.count_games_lost) > 0
                        THEN SUM(T_USER_DECK_LINK.total_life_gained_game_lost) / SUM(T_USER_DECK_LINK.count_games_lost)
                    ELSE 0
                END AS mean_total_life_gained_game_lost
                , MAX(T_USER_DECK_LINK.max_total_life_gained_game_lost) AS max_total_life_gained_game_lost
                , MIN(T_USER_DECK_LINK.min_total_life_gained_game_lost) AS min_total_life_gained_game_lost
                , SUM(T_USER_DECK_LINK.total_game_round_count) AS total_game_round_count
                , CASE
                    WHEN SUM(T_USER_DECK_LINK.count_games) > 0
                        THEN SUM(T_USER_DECK_LINK.total_game_round_count) / SUM(T_USER_DECK_LINK.count_games)
                    ELSE 0
                END AS mean_game_round_count
                , MIN(T_USER_DECK_LINK.lowest_game_round_count) AS lowest_game_round_count
                , MAX(T_USER_DECK_LINK.highest_game_round_count) AS highest_game_round_count
                , SUM(T_USER_DECK_LINK.total_game_win_round_count) AS total_game_win_round_count
                , CASE
                    WHEN SUM(T_USER_DECK_LINK.count_games_won) > 0
                        THEN SUM(T_USER_DECK_LINK.total_game_win_round_count) / SUM(T_USER_DECK_LINK.count_games_won)
                    ELSE 0
                END AS mean_game_win_round_count
                , MIN(T_USER_DECK_LINK.lowest_game_win_round_count) AS lowest_game_win_round_count
                , MAX(T_USER_DECK_LINK.highest_game_win_round_count) AS highest_game_win_round_count
                , SUM(T_USER_DECK_LINK.total_game_lose_round_count) AS total_game_lose_round_count
                , CASE
                    WHEN SUM(T_USER_DECK_LINK.count_games_lost) > 0
                        THEN SUM(T_USER_DECK_LINK.total_game_lose_round_count) / SUM(T_USER_DECK_LINK.count_games_lost)
                    ELSE 0
                END AS mean_game_lose_round_count
                , MIN(T_USER_DECK_LINK.lowest_game_lose_round_count) AS lowest_game_lose_round_count
                , MAX(T_USER_DECK_LINK.highest_game_lose_round_count) AS highest_game_lose_round_count
                , SUM(T_USER_DECK_LINK.total_game_round_survived_count) AS total_game_round_survived_count
                , CASE
                    WHEN SUM(T_USER_DECK_LINK.count_games) > 0
                        THEN SUM(T_USER_DECK_LINK.total_game_round_survived_count) / SUM(T_USER_DECK_LINK.count_games)
                    ELSE 0
                END AS mean_game_round_survived_count
                , MIN(T_USER_DECK_LINK.lowest_game_round_survived_count) AS lowest_game_round_survived_count
                , MAX(T_USER_DECK_LINK.highest_game_round_survived_count) AS highest_game_round_survived_count
                , SUM(T_USER_DECK_LINK.total_game_win_round_survived_count) AS total_game_win_round_survived_count
                , CASE
                    WHEN SUM(T_USER_DECK_LINK.count_games_won) > 0
                        THEN SUM(T_USER_DECK_LINK.total_game_win_round_survived_count) / SUM(T_USER_DECK_LINK.count_games_won)
                    ELSE 0
                END AS mean_game_win_round_survived_count
                , MIN(T_USER_DECK_LINK.lowest_game_win_round_survived_count) AS lowest_game_win_round_survived_count
                , MAX(T_USER_DECK_LINK.highest_game_win_round_survived_count) AS highest_game_win_round_survived_count
                , SUM(T_USER_DECK_LINK.total_game_lose_round_survived_count) AS total_game_lose_round_survived_count
                , CASE
                    WHEN SUM(T_USER_DECK_LINK.count_games) > 0
                        THEN SUM(T_USER_DECK_LINK.total_game_lose_round_survived_count) / SUM(T_USER_DECK_LINK.count_games_lost)
                    ELSE 0
                END AS mean_game_lose_round_survived_count
                , MIN(T_USER_DECK_LINK.lowest_game_lose_round_survived_count) AS lowest_game_lose_round_survived_count
                , MAX(T_USER_DECK_LINK.highest_game_lose_round_survived_count) AS highest_game_lose_round_survived_count
                , SUM(T_USER_DECK_LINK.total_game_duration) AS total_game_duration
                , CASE
                    WHEN SUM(T_USER_DECK_LINK.count_games) > 0
                        THEN SUM(T_USER_DECK_LINK.total_game_duration) / SUM(T_USER_DECK_LINK.count_games)
                    ELSE INTERVAL '0'
                END AS mean_game_duration
                , MIN(T_USER_DECK_LINK.shortest_game_duration) AS shortest_game_duration
                , MAX(T_USER_DECK_LINK.longest_game_duration) AS longest_game_duration
                , SUM(T_USER_DECK_LINK.total_game_win_duration) AS total_game_win_duration
                , CASE
                    WHEN SUM(T_USER_DECK_LINK.count_games_won) > 0
                        THEN SUM(T_USER_DECK_LINK.total_game_win_duration) / SUM(T_USER_DECK_LINK.count_games_won)
                    ELSE INTERVAL '0'
                END AS mean_game_win_duration
                , MIN(T_USER_DECK_LINK.shortest_game_win_duration) AS shortest_game_win_duration
                , MAX(T_USER_DECK_LINK.longest_game_win_duration) AS longest_game_win_duration
                , SUM(T_USER_DECK_LINK.total_game_lose_duration) AS total_game_lose_duration
                , CASE
                    WHEN SUM(T_USER_DECK_LINK.count_games_lost) > 0
                        THEN SUM(T_USER_DECK_LINK.total_game_lose_duration) / SUM(T_USER_DECK_LINK.count_games_lost)
                    ELSE INTERVAL '0'
                END AS mean_game_lose_duration
                , MIN(T_USER_DECK_LINK.shortest_game_lose_duration) AS shortest_game_lose_duration
                , MAX(T_USER_DECK_LINK.longest_game_lose_duration) AS longest_game_lose_duration
                , SUM(T_USER_DECK_LINK.total_commander_deaths) AS total_commander_deaths
                , CASE
                    WHEN SUM(T_USER_DECK_LINK.count_games) > 0
                        THEN SUM(T_USER_DECK_LINK.total_commander_deaths) / SUM(T_USER_DECK_LINK.count_games)
                    ELSE 0
                END AS mean_commander_deaths
                , MAX(T_USER_DECK_LINK.max_commander_deaths) AS max_commander_deaths
                , MIN(T_USER_DECK_LINK.min_commander_deaths) AS min_commander_deaths
                , SUM(T_USER_DECK_LINK.total_commander_deaths_game_won) AS total_commander_deaths_game_won
                , CASE
                    WHEN SUM(T_USER_DECK_LINK.count_games_won) > 0
                        THEN SUM(T_USER_DECK_LINK.total_commander_deaths_game_won) / SUM(T_USER_DECK_LINK.count_games_won)
                    ELSE 0
                END AS mean_commander_deaths_game_won
                , MAX(T_USER_DECK_LINK.max_commander_deaths_game_won) AS max_commander_deaths_game_won
                , MIN(T_USER_DECK_LINK.min_commander_deaths_game_won) AS min_commander_deaths_game_won
                , SUM(T_USER_DECK_LINK.total_commander_deaths_game_lost) AS total_commander_deaths_game_lost
                , CASE
                    WHEN SUM(T_USER_DECK_LINK.count_games) > 0
                        THEN SUM(T_USER_DECK_LINK.total_commander_deaths_game_lost) / SUM(T_USER_DECK_LINK.count_games)
                    ELSE 0
                END AS mean_commander_deaths_game_lost
                , MAX(T_USER_DECK_LINK.max_commander_deaths_game_lost) AS max_commander_deaths_game_lost
                , MIN(T_USER_DECK_LINK.min_commander_deaths_game_lost) AS min_commander_deaths_game_lost
                , SUM(T_USER_DECK_LINK.total_pod_sizes) AS total_pod_sizes
                , SUM(T_USER_DECK_LINK.total_opponents_faced) AS total_opponents_faced
                , CASE
                    WHEN SUM(T_USER_DECK_LINK.count_games) > 0
                        THEN SUM(T_USER_DECK_LINK.total_pod_sizes) / SUM(T_USER_DECK_LINK.count_games)
                    ELSE 0
                END AS mean_pod_size
                , MAX(T_USER_DECK_LINK.max_pod_size) AS max_pod_size
                , MIN(T_USER_DECK_LINK.min_pod_size) AS min_pod_size
                , SUM(T_USER_DECK_LINK.total_pod_sizes_won) AS total_pod_sizes_won
                , SUM(T_USER_DECK_LINK.total_opponents_beaten) AS total_opponents_beaten
                , CASE
                    WHEN SUM(T_USER_DECK_LINK.count_games) > 0
                        THEN SUM(T_USER_DECK_LINK.total_pod_sizes_won) / SUM(T_USER_DECK_LINK.count_games)
                    ELSE 0
                END AS mean_pod_size_won
                , MAX(T_USER_DECK_LINK.max_pod_size_won) AS max_pod_size_won
                , MIN(T_USER_DECK_LINK.min_pod_size_won) AS min_pod_size_won
                , SUM(T_USER_DECK_LINK.total_pod_sizes_lost) AS total_pod_sizes_lost
                , SUM(T_USER_DECK_LINK.total_opponents_lost_to) AS total_opponents_lost_to
                , CASE
                    WHEN SUM(T_USER_DECK_LINK.count_games) > 0
                        THEN SUM(T_USER_DECK_LINK.total_pod_sizes_lost) / SUM(T_USER_DECK_LINK.count_games)
                    ELSE 0
                END AS mean_pod_size_lost
                , MAX(T_USER_DECK_LINK.max_pod_size_lost) AS max_pod_size_lost
                , MIN(T_USER_DECK_LINK.min_pod_size_lost) AS min_pod_size_lost
            FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
            GROUP BY T_USER_DECK_LINK.user_id
        )
    UPDATE Temp_Statistic_Calc_User T_USER
    SET
          count_games = USER_SUMMARY.count_games
        , count_games_won = USER_SUMMARY.count_games_won
        , count_games_lost = USER_SUMMARY.count_games_lost
        , win_lose_ratio = USER_SUMMARY.win_lose_ratio
        , best_position = USER_SUMMARY.best_position
        , worst_position = USER_SUMMARY.worst_position
        , total_damage_received = USER_SUMMARY.total_damage_received
        , mean_total_damage_received = USER_SUMMARY.mean_total_damage_received
        , max_total_damage_received = USER_SUMMARY.max_total_damage_received
        , min_total_damage_received = USER_SUMMARY.min_total_damage_received
        , total_damage_received_game_win = USER_SUMMARY.total_damage_received_game_win
        , mean_total_damage_received_game_win = USER_SUMMARY.mean_total_damage_received_game_win
        , max_total_damage_received_game_win = USER_SUMMARY.max_total_damage_received_game_win
        , min_total_damage_received_game_win = USER_SUMMARY.min_total_damage_received_game_win
        , total_damage_received_game_lose = USER_SUMMARY.total_damage_received_game_lose
        , mean_total_damage_received_game_lose = USER_SUMMARY.mean_total_damage_received_game_lose
        , max_total_damage_received_game_lose = USER_SUMMARY.max_total_damage_received_game_lose
        , min_total_damage_received_game_lose = USER_SUMMARY.min_total_damage_received_game_lose
        , total_commander_damage_dealt = USER_SUMMARY.total_commander_damage_dealt
        , mean_total_commander_damage_dealt = USER_SUMMARY.mean_total_commander_damage_dealt
        , max_total_commander_damage_dealt = USER_SUMMARY.max_total_commander_damage_dealt
        , min_total_commander_damage_dealt = USER_SUMMARY.min_total_commander_damage_dealt
        , total_commander_damage_dealt_game_won = USER_SUMMARY.total_commander_damage_dealt_game_won
        , mean_total_commander_damage_dealt_won = USER_SUMMARY.mean_total_commander_damage_dealt_won
        , max_total_commander_damage_dealt_won = USER_SUMMARY.max_total_commander_damage_dealt_won
        , min_total_commander_damage_dealt_won = USER_SUMMARY.min_total_commander_damage_dealt_won
        , total_commander_damage_dealt_game_lost = USER_SUMMARY.total_commander_damage_dealt_game_lost
        , mean_total_commander_damage_dealt_lost = USER_SUMMARY.mean_total_commander_damage_dealt_lost
        , max_total_commander_damage_dealt_lost = USER_SUMMARY.max_total_commander_damage_dealt_lost
        , min_total_commander_damage_dealt_lost = USER_SUMMARY.min_total_commander_damage_dealt_lost
        , total_commander_damage_received = USER_SUMMARY.total_commander_damage_received
        , mean_total_commander_damage_received = USER_SUMMARY.mean_total_commander_damage_received
        , max_total_commander_damage_received = USER_SUMMARY.max_total_commander_damage_received
        , min_total_commander_damage_received = USER_SUMMARY.min_total_commander_damage_received
        , total_commander_damage_received_game_won = USER_SUMMARY.total_commander_damage_received_game_won
        , mean_total_commander_damage_received_won = USER_SUMMARY.mean_total_commander_damage_received_won
        , max_total_commander_damage_received_won = USER_SUMMARY.max_total_commander_damage_received_won
        , min_total_commander_damage_received_won = USER_SUMMARY.min_total_commander_damage_received_won
        , total_commander_damage_received_game_lost = USER_SUMMARY.total_commander_damage_received_game_lost
        , mean_total_commander_damage_received_lost = USER_SUMMARY.mean_total_commander_damage_received_lost
        , max_total_commander_damage_received_lost = USER_SUMMARY.max_total_commander_damage_received_lost
        , min_total_commander_damage_received_lost = USER_SUMMARY.min_total_commander_damage_received_lost
        , total_life_gained = USER_SUMMARY.total_life_gained
        , mean_total_life_gained = USER_SUMMARY.mean_total_life_gained
        , max_total_life_gained = USER_SUMMARY.max_total_life_gained
        , min_total_life_gained = USER_SUMMARY.min_total_life_gained
        , total_life_gained_game_won = USER_SUMMARY.total_life_gained_game_won
        , mean_total_life_gained_game_won = USER_SUMMARY.mean_total_life_gained_game_won
        , max_total_life_gained_game_won = USER_SUMMARY.max_total_life_gained_game_won
        , min_total_life_gained_game_won = USER_SUMMARY.min_total_life_gained_game_won
        , total_life_gained_game_lost = USER_SUMMARY.total_life_gained_game_lost
        , mean_total_life_gained_game_lost = USER_SUMMARY.mean_total_life_gained_game_lost
        , max_total_life_gained_game_lost = USER_SUMMARY.max_total_life_gained_game_lost
        , min_total_life_gained_game_lost = USER_SUMMARY.min_total_life_gained_game_lost
        , total_game_round_count = USER_SUMMARY.total_game_round_count
        , mean_game_round_count = USER_SUMMARY.mean_game_round_count
        , lowest_game_round_count = USER_SUMMARY.lowest_game_round_count
        , highest_game_round_count = USER_SUMMARY.highest_game_round_count
        , total_game_win_round_count = USER_SUMMARY.total_game_win_round_count
        , mean_game_win_round_count = USER_SUMMARY.mean_game_win_round_count
        , lowest_game_win_round_count = USER_SUMMARY.lowest_game_win_round_count
        , highest_game_win_round_count = USER_SUMMARY.highest_game_win_round_count
        , total_game_lose_round_count = USER_SUMMARY.total_game_lose_round_count
        , mean_game_lose_round_count = USER_SUMMARY.mean_game_lose_round_count
        , lowest_game_lose_round_count = USER_SUMMARY.lowest_game_lose_round_count
        , highest_game_lose_round_count = USER_SUMMARY.highest_game_lose_round_count
        , total_game_round_survived_count = USER_SUMMARY.total_game_round_survived_count
        , mean_game_round_survived_count = USER_SUMMARY.mean_game_round_survived_count
        , lowest_game_round_survived_count = USER_SUMMARY.lowest_game_round_survived_count
        , highest_game_round_survived_count = USER_SUMMARY.highest_game_round_survived_count
        , total_game_win_round_survived_count = USER_SUMMARY.total_game_win_round_survived_count
        , mean_game_win_round_survived_count = USER_SUMMARY.mean_game_win_round_survived_count
        , lowest_game_win_round_survived_count = USER_SUMMARY.lowest_game_win_round_survived_count
        , highest_game_win_round_survived_count = USER_SUMMARY.highest_game_win_round_survived_count
        , total_game_lose_round_survived_count = USER_SUMMARY.total_game_lose_round_survived_count
        , mean_game_lose_round_survived_count = USER_SUMMARY.mean_game_lose_round_survived_count
        , lowest_game_lose_round_survived_count = USER_SUMMARY.lowest_game_lose_round_survived_count
        , highest_game_lose_round_survived_count = USER_SUMMARY.highest_game_lose_round_survived_count
        , total_game_duration = USER_SUMMARY.total_game_duration
        , mean_game_duration = USER_SUMMARY.mean_game_duration
        , shortest_game_duration = USER_SUMMARY.shortest_game_duration
        , longest_game_duration = USER_SUMMARY.longest_game_duration
        , total_game_win_duration = USER_SUMMARY.total_game_win_duration
        , mean_game_win_duration = USER_SUMMARY.mean_game_win_duration
        , shortest_game_win_duration = USER_SUMMARY.shortest_game_win_duration
        , longest_game_win_duration = USER_SUMMARY.longest_game_win_duration
        , total_game_lose_duration = USER_SUMMARY.total_game_lose_duration
        , mean_game_lose_duration = USER_SUMMARY.mean_game_lose_duration
        , shortest_game_lose_duration = USER_SUMMARY.shortest_game_lose_duration
        , longest_game_lose_duration = USER_SUMMARY.longest_game_lose_duration
        , total_commander_deaths = USER_SUMMARY.total_commander_deaths
        , mean_commander_deaths = USER_SUMMARY.mean_commander_deaths
        , max_commander_deaths = USER_SUMMARY.max_commander_deaths
        , min_commander_deaths = USER_SUMMARY.min_commander_deaths
        , total_commander_deaths_game_won = USER_SUMMARY.total_commander_deaths_game_won
        , mean_commander_deaths_game_won = USER_SUMMARY.mean_commander_deaths_game_won
        , max_commander_deaths_game_won = USER_SUMMARY.max_commander_deaths_game_won
        , min_commander_deaths_game_won = USER_SUMMARY.min_commander_deaths_game_won
        , total_commander_deaths_game_lost = USER_SUMMARY.total_commander_deaths_game_lost
        , mean_commander_deaths_game_lost = USER_SUMMARY.mean_commander_deaths_game_lost
        , max_commander_deaths_game_lost = USER_SUMMARY.max_commander_deaths_game_lost
        , min_commander_deaths_game_lost = USER_SUMMARY.min_commander_deaths_game_lost
        , total_pod_sizes = USER_SUMMARY.total_pod_sizes
        , total_opponents_faced = USER_SUMMARY.total_opponents_faced
        , mean_pod_size = USER_SUMMARY.mean_pod_size
        , max_pod_size = USER_SUMMARY.max_pod_size
        , min_pod_size = USER_SUMMARY.min_pod_size
        , total_pod_sizes_won = USER_SUMMARY.total_pod_sizes_won
        , total_opponents_beaten = USER_SUMMARY.total_opponents_beaten
        , mean_pod_size_won = USER_SUMMARY.mean_pod_size_won
        , max_pod_size_won = USER_SUMMARY.max_pod_size_won
        , min_pod_size_won = USER_SUMMARY.min_pod_size_won
        , total_pod_sizes_lost = USER_SUMMARY.total_pod_sizes_lost
        , total_opponents_lost_to = USER_SUMMARY.total_opponents_lost_to
        , mean_pod_size_lost = USER_SUMMARY.mean_pod_size_lost
        , max_pod_size_lost = USER_SUMMARY.max_pod_size_lost
        , min_pod_size_lost = USER_SUMMARY.min_pod_size_lost
        , latest_game_win_on = LATEST_USER_WIN.latest_game_win_on
        , latest_game_win_pod_size = LATEST_USER_WIN.latest_game_win_pod_size
        , latest_game_lose_on = LATEST_USER_LOSE.latest_game_lose_on
        , latest_game_lose_pod_size = LATEST_USER_LOSE.latest_game_lose_pod_size
    FROM User_Summary USER_SUMMARY
    INNER JOIN Latest_User_Win LATEST_USER_WIN
        ON  USER_SUMMARY.user_id =  LATEST_USER_WIN.user_id
        AND LATEST_USER_WIN.index_win_in_user = 1
    INNER JOIN Latest_User_Lose LATEST_USER_LOSE
        ON  USER_SUMMARY.user_id =  LATEST_USER_LOSE.user_id
        AND LATEST_USER_LOSE.index_lose_in_user = 1
    WHERE USER_SUMMARY.user_id = T_USER.user_id
    ;
    
    -- Decks
    WITH
          Latest_Deck_Win AS (
            SELECT
                  T_USER_DECK_LINK.deck_id
                , T_USER_DECK_LINK.latest_game_win_pod_size
                , T_USER_DECK_LINK.latest_game_win_on
                , ROW_NUMBER() OVER (
                    PARTITION BY T_USER_DECK_LINK.deck_id
                    ORDER BY T_USER_DECK_LINK.latest_game_win_on DESC
                ) AS index_win_in_deck
            FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
            GROUP BY
                  T_USER_DECK_LINK.deck_id
                , T_USER_DECK_LINK.latest_game_win_pod_size
                , T_USER_DECK_LINK.latest_game_win_on
        )
        , Latest_Deck_Lose AS (
            SELECT
                  T_USER_DECK_LINK.deck_id
                , T_USER_DECK_LINK.latest_game_lose_pod_size
                , T_USER_DECK_LINK.latest_game_lose_on
                , ROW_NUMBER() OVER (
                    PARTITION BY T_USER_DECK_LINK.deck_id
                    ORDER BY T_USER_DECK_LINK.latest_game_lose_on DESC
                ) AS index_lose_in_deck
            FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
            GROUP BY
                  T_USER_DECK_LINK.deck_id
                , T_USER_DECK_LINK.latest_game_lose_pod_size
                , T_USER_DECK_LINK.latest_game_lose_on
        )
        , Deck_Summary AS (
            SELECT
                  T_USER_DECK_LINK.deck_id
                , SUM(T_USER_DECK_LINK.count_games) AS count_games
                , SUM(T_USER_DECK_LINK.count_games_won) AS count_games_won
                , SUM(T_USER_DECK_LINK.count_games_lost) AS count_games_lost
                , CASE
                    WHEN SUM(T_USER_DECK_LINK.count_games_lost) > 0
                        THEN SUM(T_USER_DECK_LINK.count_games_won) / SUM(T_USER_DECK_LINK.count_games_lost)
                    ELSE COALESCE(SUM(T_USER_DECK_LINK.count_games_won), 0)
                END AS win_lose_ratio
                , MIN(T_USER_DECK_LINK.best_position) AS best_position
                , MAX(T_USER_DECK_LINK.worst_position) AS worst_position
                , SUM(T_USER_DECK_LINK.total_damage_received) AS total_damage_received
                , CASE
                    WHEN SUM(T_USER_DECK_LINK.count_games) > 0
                        THEN SUM(T_USER_DECK_LINK.total_damage_received) / SUM(T_USER_DECK_LINK.count_games)
                    ELSE 0
                END AS mean_total_damage_received
                , MAX(T_USER_DECK_LINK.max_total_damage_received) AS max_total_damage_received
                , MIN(T_USER_DECK_LINK.min_total_damage_received) AS min_total_damage_received
                , SUM(T_USER_DECK_LINK.total_damage_received_game_win) AS total_damage_received_game_win
                , CASE
                    WHEN SUM(T_USER_DECK_LINK.count_games_won) > 0
                        THEN SUM(T_USER_DECK_LINK.total_damage_received_game_win) / SUM(T_USER_DECK_LINK.count_games_won)
                    ELSE 0
                END AS mean_total_damage_received_game_win
                , MAX(T_USER_DECK_LINK.max_total_damage_received_game_win) AS max_total_damage_received_game_win
                , MIN(T_USER_DECK_LINK.min_total_damage_received_game_win) AS min_total_damage_received_game_win
                , SUM(T_USER_DECK_LINK.total_damage_received_game_lose) AS total_damage_received_game_lose
                , CASE
                    WHEN SUM(T_USER_DECK_LINK.count_games_lost) > 0
                        THEN SUM(T_USER_DECK_LINK.total_damage_received_game_lose) / SUM(T_USER_DECK_LINK.count_games_lost)
                    ELSE 0
                END AS mean_total_damage_received_game_lose
                , MAX(T_USER_DECK_LINK.max_total_damage_received_game_lose) AS max_total_damage_received_game_lose
                , MIN(T_USER_DECK_LINK.min_total_damage_received_game_lose) AS min_total_damage_received_game_lose
                , SUM(T_USER_DECK_LINK.total_commander_damage_dealt) AS total_commander_damage_dealt
                , CASE
                    WHEN SUM(T_USER_DECK_LINK.count_games) > 0
                        THEN SUM(T_USER_DECK_LINK.total_commander_damage_dealt) / SUM(T_USER_DECK_LINK.count_games)
                    ELSE 0
                END AS mean_total_commander_damage_dealt
                , MAX(T_USER_DECK_LINK.max_total_commander_damage_dealt) AS max_total_commander_damage_dealt
                , MIN(T_USER_DECK_LINK.min_total_commander_damage_dealt) AS min_total_commander_damage_dealt
                , SUM(T_USER_DECK_LINK.total_commander_damage_dealt_game_won) AS total_commander_damage_dealt_game_won
                , CASE
                    WHEN SUM(T_USER_DECK_LINK.count_games_won) > 0
                        THEN SUM(T_USER_DECK_LINK.total_commander_damage_dealt_game_won) / SUM(T_USER_DECK_LINK.count_games_won)
                    ELSE 0
                END AS mean_total_commander_damage_dealt_won
                , MAX(T_USER_DECK_LINK.max_total_commander_damage_dealt_won) AS max_total_commander_damage_dealt_won
                , MIN(T_USER_DECK_LINK.min_total_commander_damage_dealt_won) AS min_total_commander_damage_dealt_won
                , SUM(T_USER_DECK_LINK.total_commander_damage_dealt_game_lost) AS total_commander_damage_dealt_game_lost
                , CASE
                    WHEN SUM(T_USER_DECK_LINK.count_games_lost) > 0
                        THEN SUM(T_USER_DECK_LINK.total_commander_damage_dealt_game_lost) / SUM(T_USER_DECK_LINK.count_games_lost)
                    ELSE 0
                END AS mean_total_commander_damage_dealt_lost
                , MAX(T_USER_DECK_LINK.max_total_commander_damage_dealt_lost) AS max_total_commander_damage_dealt_lost
                , MIN(T_USER_DECK_LINK.min_total_commander_damage_dealt_lost) AS min_total_commander_damage_dealt_lost
                , SUM(T_USER_DECK_LINK.total_commander_damage_received) AS total_commander_damage_received
                , CASE
                    WHEN SUM(T_USER_DECK_LINK.count_games) > 0
                        THEN SUM(T_USER_DECK_LINK.total_commander_damage_received) / SUM(T_USER_DECK_LINK.count_games)
                    ELSE 0
                END AS mean_total_commander_damage_received
                , MAX(T_USER_DECK_LINK.max_total_commander_damage_received) AS max_total_commander_damage_received
                , MIN(T_USER_DECK_LINK.min_total_commander_damage_received) AS min_total_commander_damage_received
                , SUM(T_USER_DECK_LINK.total_commander_damage_received_game_won) AS total_commander_damage_received_game_won
                , CASE
                    WHEN SUM(T_USER_DECK_LINK.count_games_won) > 0
                        THEN SUM(T_USER_DECK_LINK.total_commander_damage_received_game_won) / SUM(T_USER_DECK_LINK.count_games_won)
                    ELSE 0
                END AS mean_total_commander_damage_received_won
                , MAX(T_USER_DECK_LINK.max_total_commander_damage_received_won) AS max_total_commander_damage_received_won
                , MIN(T_USER_DECK_LINK.min_total_commander_damage_received_won) AS min_total_commander_damage_received_won
                , SUM(T_USER_DECK_LINK.total_commander_damage_received_game_lost) AS total_commander_damage_received_game_lost
                , CASE
                    WHEN SUM(T_USER_DECK_LINK.count_games_lost) > 0
                        THEN SUM(T_USER_DECK_LINK.total_commander_damage_received_game_lost) / SUM(T_USER_DECK_LINK.count_games_lost)
                    ELSE 0
                END AS mean_total_commander_damage_received_lost
                , MAX(T_USER_DECK_LINK.max_total_commander_damage_received_lost) AS max_total_commander_damage_received_lost
                , MIN(T_USER_DECK_LINK.min_total_commander_damage_received_lost) AS min_total_commander_damage_received_lost
                , SUM(T_USER_DECK_LINK.total_life_gained) AS total_life_gained
                , CASE
                    WHEN SUM(T_USER_DECK_LINK.count_games) > 0
                        THEN SUM(T_USER_DECK_LINK.total_life_gained) / SUM(T_USER_DECK_LINK.count_games)
                    ELSE 0
                END AS mean_total_life_gained
                , MAX(T_USER_DECK_LINK.max_total_life_gained) AS max_total_life_gained
                , MIN(T_USER_DECK_LINK.min_total_life_gained) AS min_total_life_gained
                , SUM(T_USER_DECK_LINK.total_life_gained_game_won) AS total_life_gained_game_won
                , CASE
                    WHEN SUM(T_USER_DECK_LINK.count_games_won) > 0
                        THEN SUM(T_USER_DECK_LINK.total_life_gained_game_won) / SUM(T_USER_DECK_LINK.count_games_won)
                    ELSE 0
                END AS mean_total_life_gained_game_won
                , MAX(T_USER_DECK_LINK.max_total_life_gained_game_won) AS max_total_life_gained_game_won
                , MIN(T_USER_DECK_LINK.min_total_life_gained_game_won) AS min_total_life_gained_game_won
                , SUM(T_USER_DECK_LINK.total_life_gained_game_lost) AS total_life_gained_game_lost
                , CASE
                    WHEN SUM(T_USER_DECK_LINK.count_games_lost) > 0
                        THEN SUM(T_USER_DECK_LINK.total_life_gained_game_lost) / SUM(T_USER_DECK_LINK.count_games_lost)
                    ELSE 0
                END AS mean_total_life_gained_game_lost
                , MAX(T_USER_DECK_LINK.max_total_life_gained_game_lost) AS max_total_life_gained_game_lost
                , MIN(T_USER_DECK_LINK.min_total_life_gained_game_lost) AS min_total_life_gained_game_lost
                , SUM(T_USER_DECK_LINK.total_game_round_count) AS total_game_round_count
                , CASE
                    WHEN SUM(T_USER_DECK_LINK.count_games) > 0
                        THEN SUM(T_USER_DECK_LINK.total_game_round_count) / SUM(T_USER_DECK_LINK.count_games)
                    ELSE 0
                END AS mean_game_round_count
                , MIN(T_USER_DECK_LINK.lowest_game_round_count) AS lowest_game_round_count
                , MAX(T_USER_DECK_LINK.highest_game_round_count) AS highest_game_round_count
                , SUM(T_USER_DECK_LINK.total_game_win_round_count) AS total_game_win_round_count
                , CASE
                    WHEN SUM(T_USER_DECK_LINK.count_games_won) > 0
                        THEN SUM(T_USER_DECK_LINK.total_game_win_round_count) / SUM(T_USER_DECK_LINK.count_games_won)
                    ELSE 0
                END AS mean_game_win_round_count
                , MIN(T_USER_DECK_LINK.lowest_game_win_round_count) AS lowest_game_win_round_count
                , MAX(T_USER_DECK_LINK.highest_game_win_round_count) AS highest_game_win_round_count
                , SUM(T_USER_DECK_LINK.total_game_lose_round_count) AS total_game_lose_round_count
                , CASE
                    WHEN SUM(T_USER_DECK_LINK.count_games_lost) > 0
                        THEN SUM(T_USER_DECK_LINK.total_game_lose_round_count) / SUM(T_USER_DECK_LINK.count_games_lost)
                    ELSE 0
                END AS mean_game_lose_round_count
                , MIN(T_USER_DECK_LINK.lowest_game_lose_round_count) AS lowest_game_lose_round_count
                , MAX(T_USER_DECK_LINK.highest_game_lose_round_count) AS highest_game_lose_round_count
                , SUM(T_USER_DECK_LINK.total_game_round_survived_count) AS total_game_round_survived_count
                , CASE
                    WHEN SUM(T_USER_DECK_LINK.count_games) > 0
                        THEN SUM(T_USER_DECK_LINK.total_game_round_survived_count) / SUM(T_USER_DECK_LINK.count_games)
                    ELSE 0
                END AS mean_game_round_survived_count
                , MIN(T_USER_DECK_LINK.lowest_game_round_survived_count) AS lowest_game_round_survived_count
                , MAX(T_USER_DECK_LINK.highest_game_round_survived_count) AS highest_game_round_survived_count
                , SUM(T_USER_DECK_LINK.total_game_win_round_survived_count) AS total_game_win_round_survived_count
                , CASE
                    WHEN SUM(T_USER_DECK_LINK.count_games_won) > 0
                        THEN SUM(T_USER_DECK_LINK.total_game_win_round_survived_count) / SUM(T_USER_DECK_LINK.count_games_won)
                    ELSE 0
                END AS mean_game_win_round_survived_count
                , MIN(T_USER_DECK_LINK.lowest_game_win_round_survived_count) AS lowest_game_win_round_survived_count
                , MAX(T_USER_DECK_LINK.highest_game_win_round_survived_count) AS highest_game_win_round_survived_count
                , SUM(T_USER_DECK_LINK.total_game_lose_round_survived_count) AS total_game_lose_round_survived_count
                , CASE
                    WHEN SUM(T_USER_DECK_LINK.count_games) > 0
                        THEN SUM(T_USER_DECK_LINK.total_game_lose_round_survived_count) / SUM(T_USER_DECK_LINK.count_games_lost)
                    ELSE 0
                END AS mean_game_lose_round_survived_count
                , MIN(T_USER_DECK_LINK.lowest_game_lose_round_survived_count) AS lowest_game_lose_round_survived_count
                , MAX(T_USER_DECK_LINK.highest_game_lose_round_survived_count) AS highest_game_lose_round_survived_count
                , SUM(T_USER_DECK_LINK.total_game_duration) AS total_game_duration
                , CASE
                    WHEN SUM(T_USER_DECK_LINK.count_games) > 0
                        THEN SUM(T_USER_DECK_LINK.total_game_duration) / SUM(T_USER_DECK_LINK.count_games)
                    ELSE INTERVAL '0'
                END AS mean_game_duration
                , MIN(T_USER_DECK_LINK.shortest_game_duration) AS shortest_game_duration
                , MAX(T_USER_DECK_LINK.longest_game_duration) AS longest_game_duration
                , SUM(T_USER_DECK_LINK.total_game_win_duration) AS total_game_win_duration
                , CASE
                    WHEN SUM(T_USER_DECK_LINK.count_games_won) > 0
                        THEN SUM(T_USER_DECK_LINK.total_game_win_duration) / SUM(T_USER_DECK_LINK.count_games_won)
                    ELSE INTERVAL '0'
                END AS mean_game_win_duration
                , MIN(T_USER_DECK_LINK.shortest_game_win_duration) AS shortest_game_win_duration
                , MAX(T_USER_DECK_LINK.longest_game_win_duration) AS longest_game_win_duration
                , SUM(T_USER_DECK_LINK.total_game_lose_duration) AS total_game_lose_duration
                , CASE
                    WHEN SUM(T_USER_DECK_LINK.count_games_lost) > 0
                        THEN SUM(T_USER_DECK_LINK.total_game_lose_duration) / SUM(T_USER_DECK_LINK.count_games_lost)
                    ELSE INTERVAL '0'
                END AS mean_game_lose_duration
                , MIN(T_USER_DECK_LINK.shortest_game_lose_duration) AS shortest_game_lose_duration
                , MAX(T_USER_DECK_LINK.longest_game_lose_duration) AS longest_game_lose_duration
                , SUM(T_USER_DECK_LINK.total_commander_deaths) AS total_commander_deaths
                , CASE
                    WHEN SUM(T_USER_DECK_LINK.count_games) > 0
                        THEN SUM(T_USER_DECK_LINK.total_commander_deaths) / SUM(T_USER_DECK_LINK.count_games)
                    ELSE 0
                END AS mean_commander_deaths
                , MAX(T_USER_DECK_LINK.max_commander_deaths) AS max_commander_deaths
                , MIN(T_USER_DECK_LINK.min_commander_deaths) AS min_commander_deaths
                , SUM(T_USER_DECK_LINK.total_commander_deaths_game_won) AS total_commander_deaths_game_won
                , CASE
                    WHEN SUM(T_USER_DECK_LINK.count_games_won) > 0
                        THEN SUM(T_USER_DECK_LINK.total_commander_deaths_game_won) / SUM(T_USER_DECK_LINK.count_games_won)
                    ELSE 0
                END AS mean_commander_deaths_game_won
                , MAX(T_USER_DECK_LINK.max_commander_deaths_game_won) AS max_commander_deaths_game_won
                , MIN(T_USER_DECK_LINK.min_commander_deaths_game_won) AS min_commander_deaths_game_won
                , SUM(T_USER_DECK_LINK.total_commander_deaths_game_lost) AS total_commander_deaths_game_lost
                , CASE
                    WHEN SUM(T_USER_DECK_LINK.count_games) > 0
                        THEN SUM(T_USER_DECK_LINK.total_commander_deaths_game_lost) / SUM(T_USER_DECK_LINK.count_games)
                    ELSE 0
                END AS mean_commander_deaths_game_lost
                , MAX(T_USER_DECK_LINK.max_commander_deaths_game_lost) AS max_commander_deaths_game_lost
                , MIN(T_USER_DECK_LINK.min_commander_deaths_game_lost) AS min_commander_deaths_game_lost
                , SUM(T_USER_DECK_LINK.total_pod_sizes) AS total_pod_sizes
                , SUM(T_USER_DECK_LINK.total_opponents_faced) AS total_opponents_faced
                , CASE
                    WHEN SUM(T_USER_DECK_LINK.count_games) > 0
                        THEN SUM(T_USER_DECK_LINK.total_pod_sizes) / SUM(T_USER_DECK_LINK.count_games)
                    ELSE 0
                END AS mean_pod_size
                , MAX(T_USER_DECK_LINK.max_pod_size) AS max_pod_size
                , MIN(T_USER_DECK_LINK.min_pod_size) AS min_pod_size
                , SUM(T_USER_DECK_LINK.total_pod_sizes_won) AS total_pod_sizes_won
                , SUM(T_USER_DECK_LINK.total_opponents_beaten) AS total_opponents_beaten
                , CASE
                    WHEN SUM(T_USER_DECK_LINK.count_games) > 0
                        THEN SUM(T_USER_DECK_LINK.total_pod_sizes_won) / SUM(T_USER_DECK_LINK.count_games)
                    ELSE 0
                END AS mean_pod_size_won
                , MAX(T_USER_DECK_LINK.max_pod_size_won) AS max_pod_size_won
                , MIN(T_USER_DECK_LINK.min_pod_size_won) AS min_pod_size_won
                , SUM(T_USER_DECK_LINK.total_pod_sizes_lost) AS total_pod_sizes_lost
                , SUM(T_USER_DECK_LINK.total_opponents_lost_to) AS total_opponents_lost_to
                , CASE
                    WHEN SUM(T_USER_DECK_LINK.count_games) > 0
                        THEN SUM(T_USER_DECK_LINK.total_pod_sizes_lost) / SUM(T_USER_DECK_LINK.count_games)
                    ELSE 0
                END AS mean_pod_size_lost
                , MAX(T_USER_DECK_LINK.max_pod_size_lost) AS max_pod_size_lost
                , MIN(T_USER_DECK_LINK.min_pod_size_lost) AS min_pod_size_lost
            FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
            GROUP BY T_USER_DECK_LINK.deck_id
        )
    UPDATE Temp_Statistic_Calc_Deck T_DECK
    SET
          count_games = DECK_SUMMARY.count_games
        , count_games_won = DECK_SUMMARY.count_games_won
        , count_games_lost = DECK_SUMMARY.count_games_lost
        , win_lose_ratio = DECK_SUMMARY.win_lose_ratio
        , best_position = DECK_SUMMARY.best_position
        , worst_position = DECK_SUMMARY.worst_position
        , total_damage_received = DECK_SUMMARY.total_damage_received
        , mean_total_damage_received = DECK_SUMMARY.mean_total_damage_received
        , max_total_damage_received = DECK_SUMMARY.max_total_damage_received
        , min_total_damage_received = DECK_SUMMARY.min_total_damage_received
        , total_damage_received_game_win = DECK_SUMMARY.total_damage_received_game_win
        , mean_total_damage_received_game_win = DECK_SUMMARY.mean_total_damage_received_game_win
        , max_total_damage_received_game_win = DECK_SUMMARY.max_total_damage_received_game_win
        , min_total_damage_received_game_win = DECK_SUMMARY.min_total_damage_received_game_win
        , total_damage_received_game_lose = DECK_SUMMARY.total_damage_received_game_lose
        , mean_total_damage_received_game_lose = DECK_SUMMARY.mean_total_damage_received_game_lose
        , max_total_damage_received_game_lose = DECK_SUMMARY.max_total_damage_received_game_lose
        , min_total_damage_received_game_lose = DECK_SUMMARY.min_total_damage_received_game_lose
        , total_commander_damage_dealt = DECK_SUMMARY.total_commander_damage_dealt
        , mean_total_commander_damage_dealt = DECK_SUMMARY.mean_total_commander_damage_dealt
        , max_total_commander_damage_dealt = DECK_SUMMARY.max_total_commander_damage_dealt
        , min_total_commander_damage_dealt = DECK_SUMMARY.min_total_commander_damage_dealt
        , total_commander_damage_dealt_game_won = DECK_SUMMARY.total_commander_damage_dealt_game_won
        , mean_total_commander_damage_dealt_won = DECK_SUMMARY.mean_total_commander_damage_dealt_won
        , max_total_commander_damage_dealt_won = DECK_SUMMARY.max_total_commander_damage_dealt_won
        , min_total_commander_damage_dealt_won = DECK_SUMMARY.min_total_commander_damage_dealt_won
        , total_commander_damage_dealt_game_lost = DECK_SUMMARY.total_commander_damage_dealt_game_lost
        , mean_total_commander_damage_dealt_lost = DECK_SUMMARY.mean_total_commander_damage_dealt_lost
        , max_total_commander_damage_dealt_lost = DECK_SUMMARY.max_total_commander_damage_dealt_lost
        , min_total_commander_damage_dealt_lost = DECK_SUMMARY.min_total_commander_damage_dealt_lost
        , total_commander_damage_received = DECK_SUMMARY.total_commander_damage_received
        , mean_total_commander_damage_received = DECK_SUMMARY.mean_total_commander_damage_received
        , max_total_commander_damage_received = DECK_SUMMARY.max_total_commander_damage_received
        , min_total_commander_damage_received = DECK_SUMMARY.min_total_commander_damage_received
        , total_commander_damage_received_game_won = DECK_SUMMARY.total_commander_damage_received_game_won
        , mean_total_commander_damage_received_won = DECK_SUMMARY.mean_total_commander_damage_received_won
        , max_total_commander_damage_received_won = DECK_SUMMARY.max_total_commander_damage_received_won
        , min_total_commander_damage_received_won = DECK_SUMMARY.min_total_commander_damage_received_won
        , total_commander_damage_received_game_lost = DECK_SUMMARY.total_commander_damage_received_game_lost
        , mean_total_commander_damage_received_lost = DECK_SUMMARY.mean_total_commander_damage_received_lost
        , max_total_commander_damage_received_lost = DECK_SUMMARY.max_total_commander_damage_received_lost
        , min_total_commander_damage_received_lost = DECK_SUMMARY.min_total_commander_damage_received_lost
        , total_life_gained = DECK_SUMMARY.total_life_gained
        , mean_total_life_gained = DECK_SUMMARY.mean_total_life_gained
        , max_total_life_gained = DECK_SUMMARY.max_total_life_gained
        , min_total_life_gained = DECK_SUMMARY.min_total_life_gained
        , total_life_gained_game_won = DECK_SUMMARY.total_life_gained_game_won
        , mean_total_life_gained_game_won = DECK_SUMMARY.mean_total_life_gained_game_won
        , max_total_life_gained_game_won = DECK_SUMMARY.max_total_life_gained_game_won
        , min_total_life_gained_game_won = DECK_SUMMARY.min_total_life_gained_game_won
        , total_life_gained_game_lost = DECK_SUMMARY.total_life_gained_game_lost
        , mean_total_life_gained_game_lost = DECK_SUMMARY.mean_total_life_gained_game_lost
        , max_total_life_gained_game_lost = DECK_SUMMARY.max_total_life_gained_game_lost
        , min_total_life_gained_game_lost = DECK_SUMMARY.min_total_life_gained_game_lost
        , total_game_round_count = DECK_SUMMARY.total_game_round_count
        , mean_game_round_count = DECK_SUMMARY.mean_game_round_count
        , lowest_game_round_count = DECK_SUMMARY.lowest_game_round_count
        , highest_game_round_count = DECK_SUMMARY.highest_game_round_count
        , total_game_win_round_count = DECK_SUMMARY.total_game_win_round_count
        , mean_game_win_round_count = DECK_SUMMARY.mean_game_win_round_count
        , lowest_game_win_round_count = DECK_SUMMARY.lowest_game_win_round_count
        , highest_game_win_round_count = DECK_SUMMARY.highest_game_win_round_count
        , total_game_lose_round_count = DECK_SUMMARY.total_game_lose_round_count
        , mean_game_lose_round_count = DECK_SUMMARY.mean_game_lose_round_count
        , lowest_game_lose_round_count = DECK_SUMMARY.lowest_game_lose_round_count
        , highest_game_lose_round_count = DECK_SUMMARY.highest_game_lose_round_count
        , total_game_round_survived_count = DECK_SUMMARY.total_game_round_survived_count
        , mean_game_round_survived_count = DECK_SUMMARY.mean_game_round_survived_count
        , lowest_game_round_survived_count = DECK_SUMMARY.lowest_game_round_survived_count
        , highest_game_round_survived_count = DECK_SUMMARY.highest_game_round_survived_count
        , total_game_win_round_survived_count = DECK_SUMMARY.total_game_win_round_survived_count
        , mean_game_win_round_survived_count = DECK_SUMMARY.mean_game_win_round_survived_count
        , lowest_game_win_round_survived_count = DECK_SUMMARY.lowest_game_win_round_survived_count
        , highest_game_win_round_survived_count = DECK_SUMMARY.highest_game_win_round_survived_count
        , total_game_lose_round_survived_count = DECK_SUMMARY.total_game_lose_round_survived_count
        , mean_game_lose_round_survived_count = DECK_SUMMARY.mean_game_lose_round_survived_count
        , lowest_game_lose_round_survived_count = DECK_SUMMARY.lowest_game_lose_round_survived_count
        , highest_game_lose_round_survived_count = DECK_SUMMARY.highest_game_lose_round_survived_count
        , total_game_duration = DECK_SUMMARY.total_game_duration
        , mean_game_duration = DECK_SUMMARY.mean_game_duration
        , shortest_game_duration = DECK_SUMMARY.shortest_game_duration
        , longest_game_duration = DECK_SUMMARY.longest_game_duration
        , total_game_win_duration = DECK_SUMMARY.total_game_win_duration
        , mean_game_win_duration = DECK_SUMMARY.mean_game_win_duration
        , shortest_game_win_duration = DECK_SUMMARY.shortest_game_win_duration
        , longest_game_win_duration = DECK_SUMMARY.longest_game_win_duration
        , total_game_lose_duration = DECK_SUMMARY.total_game_lose_duration
        , mean_game_lose_duration = DECK_SUMMARY.mean_game_lose_duration
        , shortest_game_lose_duration = DECK_SUMMARY.shortest_game_lose_duration
        , longest_game_lose_duration = DECK_SUMMARY.longest_game_lose_duration
        , total_commander_deaths = DECK_SUMMARY.total_commander_deaths
        , mean_commander_deaths = DECK_SUMMARY.mean_commander_deaths
        , max_commander_deaths = DECK_SUMMARY.max_commander_deaths
        , min_commander_deaths = DECK_SUMMARY.min_commander_deaths
        , total_commander_deaths_game_won = DECK_SUMMARY.total_commander_deaths_game_won
        , mean_commander_deaths_game_won = DECK_SUMMARY.mean_commander_deaths_game_won
        , max_commander_deaths_game_won = DECK_SUMMARY.max_commander_deaths_game_won
        , min_commander_deaths_game_won = DECK_SUMMARY.min_commander_deaths_game_won
        , total_commander_deaths_game_lost = DECK_SUMMARY.total_commander_deaths_game_lost
        , mean_commander_deaths_game_lost = DECK_SUMMARY.mean_commander_deaths_game_lost
        , max_commander_deaths_game_lost = DECK_SUMMARY.max_commander_deaths_game_lost
        , min_commander_deaths_game_lost = DECK_SUMMARY.min_commander_deaths_game_lost
        , total_pod_sizes = DECK_SUMMARY.total_pod_sizes
        , total_opponents_faced = DECK_SUMMARY.total_opponents_faced
        , mean_pod_size = DECK_SUMMARY.mean_pod_size
        , max_pod_size = DECK_SUMMARY.max_pod_size
        , min_pod_size = DECK_SUMMARY.min_pod_size
        , total_pod_sizes_won = DECK_SUMMARY.total_pod_sizes_won
        , total_opponents_beaten = DECK_SUMMARY.total_opponents_beaten
        , mean_pod_size_won = DECK_SUMMARY.mean_pod_size_won
        , max_pod_size_won = DECK_SUMMARY.max_pod_size_won
        , min_pod_size_won = DECK_SUMMARY.min_pod_size_won
        , total_pod_sizes_lost = DECK_SUMMARY.total_pod_sizes_lost
        , total_opponents_lost_to = DECK_SUMMARY.total_opponents_lost_to
        , mean_pod_size_lost = DECK_SUMMARY.mean_pod_size_lost
        , max_pod_size_lost = DECK_SUMMARY.max_pod_size_lost
        , min_pod_size_lost = DECK_SUMMARY.min_pod_size_lost
        , latest_game_win_on = LATEST_DECK_WIN.latest_game_win_on
        , latest_game_win_pod_size = LATEST_DECK_WIN.latest_game_win_pod_size
        , latest_game_lose_on = LATEST_DECK_LOSE.latest_game_lose_on
        , latest_game_lose_pod_size = LATEST_DECK_LOSE.latest_game_lose_pod_size
    FROM Deck_Summary DECK_SUMMARY
    INNER JOIN Latest_Deck_Win LATEST_DECK_WIN
        ON  DECK_SUMMARY.deck_id =  LATEST_DECK_WIN.deck_id
        AND LATEST_DECK_WIN.index_win_in_deck = 1
    INNER JOIN Latest_Deck_Lose LATEST_DECK_LOSE
        ON  DECK_SUMMARY.deck_id =  LATEST_DECK_LOSE.deck_id
        AND LATEST_DECK_LOSE.index_lose_in_deck = 1
    WHERE DECK_SUMMARY.deck_id = T_DECK.deck_id
    ;

    INSERT INTO Temp_Statistic_Calc_Statistic (
          entity_type_code
        , entity_record_id
        , name
        , value_bool
        , value_float
        , value_interval
        , value_text
        , value_timestamp
        , is_bool
        , is_float
        , is_interval
        , is_text
        , is_timestamp
        , active
    )
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Count games' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.count_games -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Count games won' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.count_games_won -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Count games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.count_games_lost -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Win / lose ratio' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.win_lose_ratio -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Best position' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.best_position -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Worst position' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.worst_position -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Total damage received' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.total_damage_received -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Mean total damage received' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.mean_total_damage_received -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Max total damage received' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.max_total_damage_received -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Min total damage received' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.min_total_damage_received -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Total damage received in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.total_damage_received_game_win -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Mean total damage received in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.mean_total_damage_received_game_win -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Max total damage received in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.max_total_damage_received_game_win -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Min total damage received in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.min_total_damage_received_game_win -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Total damage received in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.total_damage_received_game_lose -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Mean total damage received in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.mean_total_damage_received_game_lose -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Max total damage received in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.max_total_damage_received_game_lose -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Min total damage received in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.min_total_damage_received_game_lose -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Total commander damage dealt' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.total_commander_damage_dealt -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Mean total commander damage dealt' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.mean_total_commander_damage_dealt -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Max total commander damage dealt' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.max_total_commander_damage_dealt -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Min total commander damage dealt' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.min_total_commander_damage_dealt -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Total commander damage dealt in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.total_commander_damage_dealt_game_won -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Mean total commander damage dealt in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.mean_total_commander_damage_dealt_won -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Max total commander damage dealt in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.max_total_commander_damage_dealt_won -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Min total commander damage dealt in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.min_total_commander_damage_dealt_won -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Total commander damage dealt in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.total_commander_damage_dealt_game_lost -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Mean total commander damage dealt in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.mean_total_commander_damage_dealt_lost -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Max total commander damage dealt in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.max_total_commander_damage_dealt_lost -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Min total commander damage dealt in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.min_total_commander_damage_dealt_lost -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Total commander damage received' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.total_commander_damage_received -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Mean total commander damage received' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.mean_total_commander_damage_received -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Max total commander damage received' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.max_total_commander_damage_received -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Min total commander damage received' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.min_total_commander_damage_received -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Total commander damage received in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.total_commander_damage_received_game_won -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Mean total commander damage received in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.mean_total_commander_damage_received_won -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Max total commander damage received in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.max_total_commander_damage_received_won -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Min total commander damage received in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.min_total_commander_damage_received_won -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Total commander damage received in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.total_commander_damage_received_game_lost -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Mean total commander damage received in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.mean_total_commander_damage_received_lost -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Max total commander damage received in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.max_total_commander_damage_received_lost -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Min total commander damage received in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.min_total_commander_damage_received_lost -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Total life gained' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.total_life_gained -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Mean total life gained' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.mean_total_life_gained -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Max total life gained' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.max_total_life_gained -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Min total life gained' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.min_total_life_gained -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Total life gained in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.total_life_gained_game_won -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Mean total life gained in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.mean_total_life_gained_game_won -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Max total life gained in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.max_total_life_gained_game_won -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Min total life gained in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.min_total_life_gained_game_won -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Total life gained in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.total_life_gained_game_lost -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Mean total life gained in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.mean_total_life_gained_game_lost -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Max total life gained in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.max_total_life_gained_game_lost -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Min total life gained in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.min_total_life_gained_game_lost -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Total game round count' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.total_game_round_count -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Mean total game round count' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.mean_game_round_count -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Min total game round count' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.lowest_game_round_count -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Max total game round count' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.highest_game_round_count -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Total game round count in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.total_game_win_round_count -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Mean total game round count in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.mean_game_win_round_count -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Min total game round count in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.lowest_game_win_round_count -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Max total game round count in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.highest_game_win_round_count -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Total game round count in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.total_game_lose_round_count -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Mean total game round count in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.mean_game_lose_round_count -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Min total game round count in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.lowest_game_lose_round_count -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Max total game round count in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.highest_game_lose_round_count -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Total game round count survived' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.total_game_round_survived_count -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Mean total game round count survived' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.mean_game_round_survived_count -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Min total game round count survived' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.lowest_game_round_survived_count -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Max total game round count survived' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.highest_game_round_survived_count -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Total game round count survived in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.total_game_win_round_survived_count -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Mean total game round count survived in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.mean_game_win_round_survived_count -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Min total game round count survived in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.lowest_game_win_round_survived_count -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Max total game round count survived in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.highest_game_win_round_survived_count -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Total game round count survived in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.total_game_lose_round_survived_count -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Mean total game round count survived in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.mean_game_lose_round_survived_count -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Min total game round count survived in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.lowest_game_lose_round_survived_count -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Max total game round count survived in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.highest_game_lose_round_survived_count -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Total game duration' -- name
        , NULL::BOOLEAN -- value_bool
        , NULL::DOUBLE PRECISION -- value_float
        , T_USER_DECK_LINK.total_game_duration -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , FALSE -- is_float
        , TRUE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Mean game duration' -- name
        , NULL::BOOLEAN -- value_bool
        , NULL::DOUBLE PRECISION -- value_float
        , T_USER_DECK_LINK.mean_game_duration -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , FALSE -- is_float
        , TRUE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Min game duration' -- name
        , NULL::BOOLEAN -- value_bool
        , NULL::DOUBLE PRECISION -- value_float
        , T_USER_DECK_LINK.shortest_game_duration -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , FALSE -- is_float
        , TRUE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Max game duration' -- name
        , NULL::BOOLEAN -- value_bool
        , NULL::DOUBLE PRECISION -- value_float
        , T_USER_DECK_LINK.longest_game_duration -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , FALSE -- is_float
        , TRUE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Total game duration in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , NULL::DOUBLE PRECISION -- value_float
        , T_USER_DECK_LINK.total_game_win_duration -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , FALSE -- is_float
        , TRUE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Mean game duration in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , NULL::DOUBLE PRECISION -- value_float
        , T_USER_DECK_LINK.mean_game_win_duration -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , FALSE -- is_float
        , TRUE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Min game duration in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , NULL::DOUBLE PRECISION -- value_float
        , T_USER_DECK_LINK.shortest_game_win_duration -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , FALSE -- is_float
        , TRUE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Max game duration in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , NULL::DOUBLE PRECISION -- value_float
        , T_USER_DECK_LINK.longest_game_win_duration -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , FALSE -- is_float
        , TRUE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Total game duration in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , NULL::DOUBLE PRECISION -- value_float
        , T_USER_DECK_LINK.total_game_lose_duration -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , FALSE -- is_float
        , TRUE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Mean game duration in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , NULL::DOUBLE PRECISION -- value_float
        , T_USER_DECK_LINK.mean_game_lose_duration -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , FALSE -- is_float
        , TRUE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Min game duration in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , NULL::DOUBLE PRECISION -- value_float
        , T_USER_DECK_LINK.shortest_game_lose_duration -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , FALSE -- is_float
        , TRUE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Max game duration in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , NULL::DOUBLE PRECISION -- value_float
        , T_USER_DECK_LINK.longest_game_lose_duration -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , FALSE -- is_float
        , TRUE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Total commander deaths' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.total_commander_deaths -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Mean commander deaths' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.mean_commander_deaths -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Max commander deaths' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.max_commander_deaths -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Min commander deaths' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.min_commander_deaths -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Total commander deaths in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.total_commander_deaths_game_won -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Mean commander deaths in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.mean_commander_deaths_game_won -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Max commander deaths in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.max_commander_deaths_game_won -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Min commander deaths in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.min_commander_deaths_game_won -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Total commander deaths in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.total_commander_deaths_game_lost -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Mean commander deaths in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.mean_commander_deaths_game_lost -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Max commander deaths in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.max_commander_deaths_game_lost -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Min commander deaths in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.min_commander_deaths_game_lost -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Total pod sizes' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.total_pod_sizes -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Total opponents faced' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.total_opponents_faced -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Mean pod size' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.mean_pod_size -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Max pod size' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.max_pod_size -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Min pod size' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.min_pod_size -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Total pod sizes in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.total_pod_sizes_won -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Total opponents beaten' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.total_opponents_beaten -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Mean pod size in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.mean_pod_size_won -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Max pod size in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.max_pod_size_won -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Min pod size in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.min_pod_size_won -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Total pod sizes in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.total_pod_sizes_lost -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Total opponents lost to' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.total_opponents_lost_to -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Mean pod size in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.mean_pod_size_lost -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Max pod size in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.max_pod_size_lost -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_user_deck_link_entity_type_code -- entity_type_code
        , CONCAT(
              '{ user_id: '
            , CAST(T_USER_DECK_LINK.user_id AS VARCHAR)
            , ', deck_id: '
            , CAST(T_USER_DECK_LINK.deck_id AS VARCHAR)
            , '}'
        ) -- entity_record_id
        , 'Min pod size in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER_DECK_LINK.min_pod_size_lost -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User_Deck_Link T_USER_DECK_LINK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Count games' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.count_games -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Count games won' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.count_games_won -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Count games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.count_games_lost -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Win / lose ratio' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.win_lose_ratio -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Best position' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.best_position -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Worst position' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.worst_position -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Total damage received' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.total_damage_received -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Mean total damage received' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.mean_total_damage_received -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Max total damage received' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.max_total_damage_received -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Min total damage received' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.min_total_damage_received -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Total damage received in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.total_damage_received_game_win -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Mean total damage received in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.mean_total_damage_received_game_win -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Max total damage received in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.max_total_damage_received_game_win -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Min total damage received in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.min_total_damage_received_game_win -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Total damage received in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.total_damage_received_game_lose -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Mean total damage received in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.mean_total_damage_received_game_lose -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Max total damage received in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.max_total_damage_received_game_lose -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Min total damage received in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.min_total_damage_received_game_lose -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Total commander damage dealt' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.total_commander_damage_dealt -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Mean total commander damage dealt' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.mean_total_commander_damage_dealt -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Max total commander damage dealt' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.max_total_commander_damage_dealt -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Min total commander damage dealt' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.min_total_commander_damage_dealt -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Total commander damage dealt in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.total_commander_damage_dealt_game_won -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Mean total commander damage dealt in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.mean_total_commander_damage_dealt_won -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Max total commander damage dealt in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.max_total_commander_damage_dealt_won -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Min total commander damage dealt in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.min_total_commander_damage_dealt_won -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Total commander damage dealt in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.total_commander_damage_dealt_game_lost -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Mean total commander damage dealt in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.mean_total_commander_damage_dealt_lost -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Max total commander damage dealt in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.max_total_commander_damage_dealt_lost -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Min total commander damage dealt in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.min_total_commander_damage_dealt_lost -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Total commander damage received' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.total_commander_damage_received -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Mean total commander damage received' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.mean_total_commander_damage_received -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Max total commander damage received' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.max_total_commander_damage_received -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Min total commander damage received' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.min_total_commander_damage_received -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Total commander damage received in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.total_commander_damage_received_game_won -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Mean total commander damage received in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.mean_total_commander_damage_received_won -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Max total commander damage received in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.max_total_commander_damage_received_won -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Min total commander damage received in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.min_total_commander_damage_received_won -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Total commander damage received in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.total_commander_damage_received_game_lost -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Mean total commander damage received in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.mean_total_commander_damage_received_lost -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Max total commander damage received in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.max_total_commander_damage_received_lost -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Min total commander damage received in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.min_total_commander_damage_received_lost -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Total life gained' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.total_life_gained -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Mean total life gained' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.mean_total_life_gained -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Max total life gained' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.max_total_life_gained -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Min total life gained' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.min_total_life_gained -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Total life gained in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.total_life_gained_game_won -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Mean total life gained in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.mean_total_life_gained_game_won -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Max total life gained in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.max_total_life_gained_game_won -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Min total life gained in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.min_total_life_gained_game_won -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Total life gained in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.total_life_gained_game_lost -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Mean total life gained in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.mean_total_life_gained_game_lost -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Max total life gained in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.max_total_life_gained_game_lost -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Min total life gained in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.min_total_life_gained_game_lost -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Total game round count' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.total_game_round_count -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Mean total game round count' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.mean_game_round_count -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Min total game round count' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.lowest_game_round_count -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Max total game round count' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.highest_game_round_count -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Total game round count in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.total_game_win_round_count -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Mean total game round count in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.mean_game_win_round_count -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Min total game round count in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.lowest_game_win_round_count -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Max total game round count in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.highest_game_win_round_count -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Total game round count in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.total_game_lose_round_count -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Mean total game round count in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.mean_game_lose_round_count -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Min total game round count in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.lowest_game_lose_round_count -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Max total game round count in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.highest_game_lose_round_count -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Total game round count survived' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.total_game_round_survived_count -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Mean total game round count survived' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.mean_game_round_survived_count -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Min total game round count survived' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.lowest_game_round_survived_count -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Max total game round count survived' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.highest_game_round_survived_count -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Total game round count survived in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.total_game_win_round_survived_count -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Mean total game round count survived in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.mean_game_win_round_survived_count -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Min total game round count survived in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.lowest_game_win_round_survived_count -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Max total game round count survived in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.highest_game_win_round_survived_count -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Total game round count survived in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.total_game_lose_round_survived_count -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Mean total game round count survived in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.mean_game_lose_round_survived_count -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Min total game round count survived in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.lowest_game_lose_round_survived_count -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Max total game round count survived in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.highest_game_lose_round_survived_count -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Total game duration' -- name
        , NULL::BOOLEAN -- value_bool
        , NULL::DOUBLE PRECISION -- value_float
        , T_DECK.total_game_duration -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , FALSE -- is_float
        , TRUE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Mean game duration' -- name
        , NULL::BOOLEAN -- value_bool
        , NULL::DOUBLE PRECISION -- value_float
        , T_DECK.mean_game_duration -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , FALSE -- is_float
        , TRUE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Min game duration' -- name
        , NULL::BOOLEAN -- value_bool
        , NULL::DOUBLE PRECISION -- value_float
        , T_DECK.shortest_game_duration -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , FALSE -- is_float
        , TRUE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Max game duration' -- name
        , NULL::BOOLEAN -- value_bool
        , NULL::DOUBLE PRECISION -- value_float
        , T_DECK.longest_game_duration -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , FALSE -- is_float
        , TRUE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Total game duration in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , NULL::DOUBLE PRECISION -- value_float
        , T_DECK.total_game_win_duration -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , FALSE -- is_float
        , TRUE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Mean game duration in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , NULL::DOUBLE PRECISION -- value_float
        , T_DECK.mean_game_win_duration -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , FALSE -- is_float
        , TRUE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Min game duration in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , NULL::DOUBLE PRECISION -- value_float
        , T_DECK.shortest_game_win_duration -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , FALSE -- is_float
        , TRUE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Max game duration in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , NULL::DOUBLE PRECISION -- value_float
        , T_DECK.longest_game_win_duration -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , FALSE -- is_float
        , TRUE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Total game duration in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , NULL::DOUBLE PRECISION -- value_float
        , T_DECK.total_game_lose_duration -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , FALSE -- is_float
        , TRUE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Mean game duration in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , NULL::DOUBLE PRECISION -- value_float
        , T_DECK.mean_game_lose_duration -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , FALSE -- is_float
        , TRUE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Min game duration in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , NULL::DOUBLE PRECISION -- value_float
        , T_DECK.shortest_game_lose_duration -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , FALSE -- is_float
        , TRUE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Max game duration in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , NULL::DOUBLE PRECISION -- value_float
        , T_DECK.longest_game_lose_duration -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , FALSE -- is_float
        , TRUE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Total commander deaths' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.total_commander_deaths -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Mean commander deaths' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.mean_commander_deaths -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Max commander deaths' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.max_commander_deaths -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Min commander deaths' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.min_commander_deaths -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Total commander deaths in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.total_commander_deaths_game_won -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Mean commander deaths in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.mean_commander_deaths_game_won -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Max commander deaths in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.max_commander_deaths_game_won -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Min commander deaths in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.min_commander_deaths_game_won -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Total commander deaths in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.total_commander_deaths_game_lost -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Mean commander deaths in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.mean_commander_deaths_game_lost -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Max commander deaths in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.max_commander_deaths_game_lost -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Min commander deaths in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.min_commander_deaths_game_lost -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Total pod sizes' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.total_pod_sizes -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Total opponents faced' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.total_opponents_faced -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Mean pod size' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.mean_pod_size -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Max pod size' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.max_pod_size -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Min pod size' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.min_pod_size -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Total pod sizes in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.total_pod_sizes_won -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Total opponents beaten' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.total_opponents_beaten -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Mean pod size in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.mean_pod_size_won -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Max pod size in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.max_pod_size_won -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Min pod size in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.min_pod_size_won -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Total pod sizes in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.total_pod_sizes_lost -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Total opponents lost to' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.total_opponents_lost_to -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Mean pod size in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.mean_pod_size_lost -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Max pod size in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.max_pod_size_lost -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_deck_entity_type_code -- entity_type_code
        , T_DECK.deck_id::TEXT -- entity_record_id
        , 'Min pod size in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , T_DECK.min_pod_size_lost -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_Deck T_DECK
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Count games' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.count_games -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Count games won' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.count_games_won -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Count games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.count_games_lost -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Win / lose ratio' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.win_lose_ratio -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Best position' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.best_position -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Worst position' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.worst_position -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Total damage received' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.total_damage_received -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Mean total damage received' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.mean_total_damage_received -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Max total damage received' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.max_total_damage_received -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Min total damage received' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.min_total_damage_received -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Total damage received in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.total_damage_received_game_win -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Mean total damage received in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.mean_total_damage_received_game_win -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Max total damage received in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.max_total_damage_received_game_win -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Min total damage received in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.min_total_damage_received_game_win -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Total damage received in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.total_damage_received_game_lose -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Mean total damage received in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.mean_total_damage_received_game_lose -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Max total damage received in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.max_total_damage_received_game_lose -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Min total damage received in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.min_total_damage_received_game_lose -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Total commander damage dealt' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.total_commander_damage_dealt -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Mean total commander damage dealt' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.mean_total_commander_damage_dealt -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Max total commander damage dealt' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.max_total_commander_damage_dealt -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Min total commander damage dealt' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.min_total_commander_damage_dealt -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Total commander damage dealt in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.total_commander_damage_dealt_game_won -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Mean total commander damage dealt in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.mean_total_commander_damage_dealt_won -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Max total commander damage dealt in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.max_total_commander_damage_dealt_won -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Min total commander damage dealt in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.min_total_commander_damage_dealt_won -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Total commander damage dealt in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.total_commander_damage_dealt_game_lost -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Mean total commander damage dealt in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.mean_total_commander_damage_dealt_lost -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Max total commander damage dealt in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.max_total_commander_damage_dealt_lost -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Min total commander damage dealt in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.min_total_commander_damage_dealt_lost -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Total commander damage received' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.total_commander_damage_received -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Mean total commander damage received' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.mean_total_commander_damage_received -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Max total commander damage received' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.max_total_commander_damage_received -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Min total commander damage received' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.min_total_commander_damage_received -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Total commander damage received in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.total_commander_damage_received_game_won -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Mean total commander damage received in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.mean_total_commander_damage_received_won -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Max total commander damage received in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.max_total_commander_damage_received_won -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Min total commander damage received in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.min_total_commander_damage_received_won -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Total commander damage received in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.total_commander_damage_received_game_lost -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Mean total commander damage received in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.mean_total_commander_damage_received_lost -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Max total commander damage received in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.max_total_commander_damage_received_lost -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Min total commander damage received in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.min_total_commander_damage_received_lost -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Total life gained' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.total_life_gained -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Mean total life gained' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.mean_total_life_gained -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Max total life gained' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.max_total_life_gained -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Min total life gained' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.min_total_life_gained -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Total life gained in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.total_life_gained_game_won -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Mean total life gained in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.mean_total_life_gained_game_won -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Max total life gained in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.max_total_life_gained_game_won -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Min total life gained in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.min_total_life_gained_game_won -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Total life gained in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.total_life_gained_game_lost -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Mean total life gained in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.mean_total_life_gained_game_lost -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Max total life gained in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.max_total_life_gained_game_lost -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Min total life gained in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.min_total_life_gained_game_lost -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Total game round count' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.total_game_round_count -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Mean total game round count' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.mean_game_round_count -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Min total game round count' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.lowest_game_round_count -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Max total game round count' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.highest_game_round_count -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Total game round count in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.total_game_win_round_count -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Mean total game round count in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.mean_game_win_round_count -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Min total game round count in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.lowest_game_win_round_count -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Max total game round count in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.highest_game_win_round_count -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Total game round count in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.total_game_lose_round_count -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Mean total game round count in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.mean_game_lose_round_count -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Min total game round count in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.lowest_game_lose_round_count -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Max total game round count in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.highest_game_lose_round_count -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Total game round count survived' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.total_game_round_survived_count -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Mean total game round count survived' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.mean_game_round_survived_count -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Min total game round count survived' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.lowest_game_round_survived_count -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Max total game round count survived' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.highest_game_round_survived_count -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Total game round count survived in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.total_game_win_round_survived_count -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Mean total game round count survived in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.mean_game_win_round_survived_count -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Min total game round count survived in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.lowest_game_win_round_survived_count -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Max total game round count survived in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.highest_game_win_round_survived_count -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Total game round count survived in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.total_game_lose_round_survived_count -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Mean total game round count survived in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.mean_game_lose_round_survived_count -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Min total game round count survived in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.lowest_game_lose_round_survived_count -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Max total game round count survived in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.highest_game_lose_round_survived_count -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Total game duration' -- name
        , NULL::BOOLEAN -- value_bool
        , NULL::DOUBLE PRECISION -- value_float
        , T_USER.total_game_duration -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , FALSE -- is_float
        , TRUE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Mean game duration' -- name
        , NULL::BOOLEAN -- value_bool
        , NULL::DOUBLE PRECISION -- value_float
        , T_USER.mean_game_duration -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , FALSE -- is_float
        , TRUE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Min game duration' -- name
        , NULL::BOOLEAN -- value_bool
        , NULL::DOUBLE PRECISION -- value_float
        , T_USER.shortest_game_duration -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , FALSE -- is_float
        , TRUE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Max game duration' -- name
        , NULL::BOOLEAN -- value_bool
        , NULL::DOUBLE PRECISION -- value_float
        , T_USER.longest_game_duration -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , FALSE -- is_float
        , TRUE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Total game duration in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , NULL::DOUBLE PRECISION -- value_float
        , T_USER.total_game_win_duration -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , FALSE -- is_float
        , TRUE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Mean game duration in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , NULL::DOUBLE PRECISION -- value_float
        , T_USER.mean_game_win_duration -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , FALSE -- is_float
        , TRUE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Min game duration in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , NULL::DOUBLE PRECISION -- value_float
        , T_USER.shortest_game_win_duration -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , FALSE -- is_float
        , TRUE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Max game duration in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , NULL::DOUBLE PRECISION -- value_float
        , T_USER.longest_game_win_duration -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , FALSE -- is_float
        , TRUE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Total game duration in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , NULL::DOUBLE PRECISION -- value_float
        , T_USER.total_game_lose_duration -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , FALSE -- is_float
        , TRUE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Mean game duration in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , NULL::DOUBLE PRECISION -- value_float
        , T_USER.mean_game_lose_duration -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , FALSE -- is_float
        , TRUE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Min game duration in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , NULL::DOUBLE PRECISION -- value_float
        , T_USER.shortest_game_lose_duration -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , FALSE -- is_float
        , TRUE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Max game duration in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , NULL::DOUBLE PRECISION -- value_float
        , T_USER.longest_game_lose_duration -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , FALSE -- is_float
        , TRUE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Total commander deaths' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.total_commander_deaths -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Mean commander deaths' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.mean_commander_deaths -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Max commander deaths' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.max_commander_deaths -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Min commander deaths' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.min_commander_deaths -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Total commander deaths in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.total_commander_deaths_game_won -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Mean commander deaths in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.mean_commander_deaths_game_won -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Max commander deaths in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.max_commander_deaths_game_won -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Min commander deaths in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.min_commander_deaths_game_won -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Total commander deaths in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.total_commander_deaths_game_lost -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Mean commander deaths in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.mean_commander_deaths_game_lost -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Max commander deaths in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.max_commander_deaths_game_lost -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Min commander deaths in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.min_commander_deaths_game_lost -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Total pod sizes' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.total_pod_sizes -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Total opponents faced' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.total_opponents_faced -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Mean pod size' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.mean_pod_size -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Max pod size' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.max_pod_size -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Min pod size' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.min_pod_size -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Total pod sizes in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.total_pod_sizes_won -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Total opponents beaten' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.total_opponents_beaten -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Mean pod size in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.mean_pod_size_won -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Max pod size in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.max_pod_size_won -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Min pod size in games won' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.min_pod_size_won -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Total pod sizes in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.total_pod_sizes_lost -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Total opponents lost to' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.total_opponents_lost_to -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Mean pod size in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.mean_pod_size_lost -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Max pod size in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.max_pod_size_lost -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    UNION
    SELECT
          v_user_entity_type_code -- entity_type_code
        , T_USER.user_id::TEXT -- entity_record_id
        , 'Min pod size in games lost' -- name
        , NULL::BOOLEAN -- value_bool
        , T_USER.min_pod_size_lost -- value_float
        , NULL::INTERVAL -- value_interval
        , NULL::TEXT -- value_text
        , NULL::TIMESTAMP -- value_timestamp
        , FALSE -- is_bool
        , TRUE -- is_float
        , FALSE -- is_interval
        , FALSE -- is_text
        , FALSE -- is_timestamp
        , TRUE -- active
    FROM Temp_Statistic_Calc_User T_USER
    ;

	-- Nothing to save
	IF NOT EXISTS (SELECT * FROM Temp_Statistic_Calc_Statistic LIMIT 1) THEN
		INSERT INTO Temp_Statistic_Calc_Error (
			  error_type_id
			, message
		)
		VALUES (
			  v_warning_error_type_id
			, 'Nothing to save.'
		);
	END IF;

	-- Outputs
	-- Change Set
	INSERT INTO tcg.public.TCG_Change_Set (
		  comment
		, updated_last_by_user_id
	)
	VALUES (
		  v_comment
		, v_user_id
	)
	RETURNING change_set_id INTO v_change_set_id
	;
	
	IF NOT EXISTS (SELECT * FROM Temp_Statistic_Calc_Error T_ERROR WHERE T_ERROR.error_type_id <> v_warning_error_type_id LIMIT 1) THEN
		
		DELETE FROM tcg.public.TCG_Statistic;

		-- Statistic
		INSERT INTO tcg.public.TCG_Statistic (
              entity_type_code
            , entity_record_id
            , name
            , value_bool
            , value_float
			, value_interval
            , value_text
            , value_timestamp
            , is_bool
            , is_float
			, is_interval
            , is_text
            , is_timestamp
            , display_order
            , active
            , created_on
            , created_by_user_id
            , updated_last_on
            , updated_last_by_user_id
            , change_set_id
		)
		SELECT
              T_STATISTIC.entity_type_code
            , T_STATISTIC.entity_record_id
            , T_STATISTIC.name
            , T_STATISTIC.value_bool
            , T_STATISTIC.value_float
            , T_STATISTIC.value_interval
            , T_STATISTIC.value_text
            , T_STATISTIC.value_timestamp
            , T_STATISTIC.is_bool
            , T_STATISTIC.is_float
            , T_STATISTIC.is_interval
            , T_STATISTIC.is_text
            , T_STATISTIC.is_timestamp
            , T_STATISTIC.temp_statistic_id -- display_order
		    , T_STATISTIC.active
			, v_time_start -- created_on
			, v_user_id -- created_by_user_id
			, v_time_start -- updated_last_on
			, v_user_id -- updated_last_by_user_id
		    , v_change_set_id -- change_set_id
		FROM Temp_Statistic_Calc_Statistic T_STATISTIC
		WHERE T_STATISTIC.active = TRUE
		;
	
	ELSE
		-- Error
		INSERT INTO tcg.public.Error (
			  guid
			, error_type_id
			, message
			, display_order
			, created_on
			, created_by_user_id
			, updated_last_on
			, updated_last_by_user_id
			, change_set_id
		)
		SELECT
			  v_guid
			, T_ERROR.error_type_id
			, T_ERROR.message
			, T_ERROR.temp_id
			, v_time_start
			, v_user_id
			, v_time_start
			, v_user_id
			, v_change_set_id
		FROM Temp_Statistic_Calc_Error T_ERROR
		LEFT JOIN tcg.public.Error_Type ERROR_TYPE ON T_ERROR.error_type_id = ERROR_TYPE.error_type_id
		ORDER BY T_ERROR.temp_id
		;
	END IF;

    COMMIT;
	
	o_success := NOT EXISTS (
		SELECT *
		FROM Temp_Statistic_Calc_Error T_ERROR
		WHERE T_ERROR.error_type_id <> v_warning_error_type_id
		LIMIT 1
	);
	
	DROP TABLE IF EXISTS Temp_Statistic_Calc_Statistic;
	DROP TABLE IF EXISTS Temp_Statistic_Calc_Deck;
	DROP TABLE IF EXISTS Temp_Statistic_Calc_Game;
	DROP TABLE IF EXISTS Temp_Statistic_Calc_Player;
	DROP TABLE IF EXISTS Temp_Statistic_Calc_User;
	DROP TABLE IF EXISTS Temp_Statistic_Calc_User_Deck_Link;
	DROP TABLE IF EXISTS Temp_Statistic_Calc_Round;
	DROP TABLE IF EXISTS Temp_Statistic_Calc_Round_Player_Damage;
    DROP TABLE IF EXISTS Temp_Statistic_Calc_Player_Round_Link;
	DROP TABLE IF EXISTS Temp_Statistic_Calc_Error;
END;
$$;

-- Call it with:
DO $$
DECLARE
	v_comment TEXT := 'MTG Statistic Calc.';
	v_guid UUID;
    v_user_id INT := 3;
    v_success BOOLEAN;
BEGIN
	v_guid := '6307bed6-73a1-41ab-9a90-79e18e14dd81'::UUID; -- gen_random_uuid();

    CALL tcg.public.USP_TCG_Statistic_Calc (
		  a_comment := v_comment -- a_comment
		, a_guid := v_guid -- a_guid
		, a_user_id := v_user_id -- a_user_id
		, o_success := v_success -- o_success
	);
    RAISE NOTICE 'Success: %', CASE WHEN v_success THEN 'TRUE' ELSE 'FALSE' END;
END;
$$;

/*
SELECT *
FROM tcg.public.TCG_Statistic
;
;
SELECT INTERVAL '0'
* /
SELECT COUNT(*) 
FROM tcg.public.TCG_Statistic STATISTIC
;
SELECT *
FROM tcg.public.TCG_User TCG_USER
;
SELECT *
-- DELETE
FROM tcg.public.TCG_Statistic STATISTIC
where
		STATISTIC.NAME like '%life%'
	and STATISTIC.entity_record_id in ('3', '4')
ORDER BY
	STATISTIC.entity_type_code ASC 
	, STATISTIC.entity_record_id asc
	, STATISTIC.NAME
*/
