SELECT MAX(CASE WHEN CHANNEL IN ('00113','00114') THEN 'COOLOTS' ELSE 'CHATON') GROUP_CODE, MAX(TO_CHAR(REGDATE, 'YYYYMMDD')) REG_DATE, MAX(CHANNEL) AS CHANNEL, MAX(SECT) AS SECT, COUNT(*) AS COUNT, COUNT(DECODE(STATUS_COD,'AR')) AR_COUNT, COUNT(DECODE(STATUS_COD,'NR')) NR_COUNT, FLOOR(AVG(REPLY_REGDATE - REGDATE) / 86400) AVG_AR_DAY TO_CHAR(TO_DATE(MOD(AVG(REPLY_REGDATE - REGDATE),86400),'SSSSS'),'HH24:MI:SS') AVG_AR_TIME FROM MAIL_CONSULT A GROUP BY TO_CHAR(REGDATE, 'YYYYMMDD'), CHANNEL, SECT
SELECT group_code , reg_date , channel , sect , count , ar_count , nr_count , FLOOR(sec / (24*60*60)) || ' ' || TO_CHAR(TO_DATE(MOD(sec, 24*60*60), 'sssss'), 'hh24:mi:ss') AS avg_ar_time FROM ( SELECT CASE WHEN channel IN ('00113', '00114') THEN 'COOLOTS' ELSE 'CHATON' END AS group_code , TO_CHAR(regdate, 'yyyymmdd') AS reg_date , channel , sect , COUNT(*) AS count , COUNT(CASE WHEN status_code = 'AR' THEN 1 END) AS ar_count , COUNT(CASE WHEN status_code = 'NR' THEN 1 END) AS nr_count , ROUND(AVG(reply_regdate - regdate)*24*60*60) AS sec FROM mail_consult a GROUP BY TO_CHAR(regdate, 'yyyymmdd') reg_date , channel , sect ) ;
평균시간이 하루를 넘으면 오류나지 않을까요..?