두번째 쿼리는 특정 어카운트의 날짜별 이력 확인
mysql> select distinct account_id, date_format(date_add(date_time, interval 9 hour), '%Y-%m-%d') as DATE_KST, support_level from support_level_history order by account_id, DATE_KST;
mysql> select distinct account_id, date_format(date_add(date_time, interval 9 hour), '%Y-%m-%d') as DATE_KST, support_level from support_level_history where account_id = '000000000000' order by account_id, DATE_KST;
mysql>
다음 쿼리로 조회되는 건은 Support Plan의 변경이 있었던 날임
mysql> select account_id, DATE_KST, count(distinct support_level) as count from (select account_id, date_format(date_add(date_time, interval 9 hour), '%Y-%m-%d') as DATE_KST, support_level from support_level_history) as data group by 1,2 having count > 1;
mysql> SELECT DISTINCT v.account_id as 'Account ID', v.date_kst as 'Date(KST)', before_change.support_level AS 'Before', after_change.support_level AS 'After', Date_format(int_from.time, '%H:%i:%s') AS 'Time1(KST)', Date_format(int_to.time, '%H:%i:%s') AS 'Time2(KST)' FROM v_support_level_change_history AS v, (SELECT a.account_id, a.date_kst, support_level FROM v_support_level_change_history a, (SELECT account_id, date_kst, Min(min_time) AS start, Max(max_time) AS end FROM v_support_level_change_history GROUP BY 1, 2) b WHERE a.account_id = b.account_id AND a.date_kst = b.date_kst AND a.min_time = b.start) AS before_change, (SELECT a.account_id, a.date_kst, support_level FROM v_support_level_change_history a, (SELECT account_id, date_kst, Min(min_time) AS start, Max(max_time) AS end FROM v_support_level_change_history GROUP BY 1, 2) b WHERE a.account_id = b.account_id AND a.date_kst = b.date_kst AND a.max_time = b.end) AS after_change, (SELECT a.account_id, a.date_kst, Max(max_time) AS time FROM v_support_level_change_history a, (SELECT account_id, date_kst, Min(min_time) AS start, Max(max_time) AS end FROM v_support_level_change_history GROUP BY 1, 2) b WHERE a.account_id = b.account_id AND a.date_kst = b.date_kst AND a.min_time = b.start GROUP BY 1, 2) AS int_from, (SELECT a.account_id, a.date_kst, Min(min_time) AS time FROM v_support_level_change_history a, (SELECT account_id, date_kst, Min(min_time) AS start, Max(max_time) AS end FROM v_support_level_change_history GROUP BY 1, 2) b WHERE a.account_id = b.account_id AND a.date_kst = b.date_kst AND a.max_time = b.end GROUP BY 1, 2) AS int_to WHERE v.account_id = before_change.account_id AND v.date_kst = before_change.date_kst AND v.account_id = after_change.account_id AND v.date_kst = after_change.date_kst AND v.account_id = int_from.account_id AND v.date_kst = int_from.date_kst AND v.account_id = int_to.account_id AND v.date_kst = int_to.date_kst ;
mysql>