-- 불필요한 함수 사용이 너무 많네요. 거추장스러운 함수는 다 제거했습니다. WITH v_time AS ( SELECT LPAD(LEVEL - 1, 2, '0') hour FROM dual CONNECT BY LEVEL <= 24 ) SELECT t1.hour , DECODE(COUNT(t2.hour), 0, 'X', 'O') exist FROM v_time t1 LEFT JOIN t_test t2 ON t1.hour = t2.hour AND t2.enterdate >= '20120903' AND t2.enterdate <= '20120905' GROUP BY t1.hour ORDER BY t1.hour ;