INSERT INTO `t_game_config` (`u_level`, `set_type`, `set_type_val`, `title`) VALUES ('0', 'sd_last_bet_his', '2022-11-18 00:30:00', 'sd 베팅목록 호출시간');

USE `mydb`;
CREATE 
     OR REPLACE ALGORITHM = UNDEFINED 
    SQL SECURITY DEFINER
VIEW `day_sd_casino_slot_view` AS
    SELECT 
        'bet_tot_sd_casino' AS `stype`,
        IFNULL(SUM(CASE
                    WHEN `CBH`.`TRANSACTION_TYPE` = 'Bet' THEN `CBH`.`BET_MNY`
                END),
                0) AS `total_bet_money`,
        IFNULL(SUM(CASE
                    WHEN `CBH`.`TRANSACTION_TYPE` = 'Win' THEN `CBH`.`RSLT_MNY`
                END),
                0) AS `total_win_money`,
        0 AS `total_ing_bet_money`
    FROM
        (`member` `MB`
        LEFT JOIN `SD_CSN_BET_HIST` `CBH` ON (`MB`.`idx` = `CBH`.`MBR_IDX`))
    WHERE
        `CBH`.`REG_DTM` >= DATE_FORMAT(CURRENT_TIMESTAMP(), '%Y-%m-%d 00:00:00')
            AND `CBH`.`REG_DTM` <= DATE_FORMAT(CURRENT_TIMESTAMP(), '%Y-%m-%d 23:59:59')
            AND `MB`.`level` <> 9
            AND `MB`.`u_business` = 1
            AND `CBH`.`CATEGORY` NOT IN ('Slots') 
    UNION ALL SELECT 
        'bet_tot_sd_slot' AS `stype`,
        IFNULL(SUM(CASE
                    WHEN `CBH`.`TRANSACTION_TYPE` = 'Bet' THEN `CBH`.`BET_MNY`
                END),
                0) AS `total_bet_money`,
        IFNULL(SUM(CASE
                    WHEN `CBH`.`TRANSACTION_TYPE` = 'Win' THEN `CBH`.`RSLT_MNY`
                END),
                0) AS `total_win_money`,
        0 AS `total_ing_bet_money`
    FROM
        (`member` `MB`
        LEFT JOIN `SD_CSN_BET_HIST` `CBH` ON (`MB`.`idx` = `CBH`.`MBR_IDX`))
    WHERE
        `CBH`.`REG_DTM` >= DATE_FORMAT(CURRENT_TIMESTAMP(), '%Y-%m-%d 00:00:00')
            AND `CBH`.`REG_DTM` <= DATE_FORMAT(CURRENT_TIMESTAMP(), '%Y-%m-%d 23:59:59')
            AND `MB`.`level` <> 9
            AND `MB`.`u_business` = 1
            AND `CBH`.`CATEGORY` IN ('Slots');
