๋ฌธ์
ํ์ด
SELECT A.HOUR, COUNT(B.DATETIME) COUNT
FROM (SELECT LEVEL - 1 AS HOUR FROM DUAL CONNECT BY LEVEL <= 24) A LEFT JOIN
ANIMAL_OUTS B ON A.HOUR = TO_CHAR(B.DATETIME, 'HH24')
GROUP BY A.HOUR
ORDER BY 1
;
- COUNT(*)์ ํ๋ฉด ๋ฐ์ดํฐ๊ฐ ์์ด๋ 1๋ก ์ถ๋ ฅํ๊ธฐ ๋๋ฌธ์, COUNT(B.DATETIME)์ผ๋ก ์์ฑํ์ต๋๋ค.
- 0๋ถํฐ 23์ ๊ฐ์ง ํ ์ด๋ธ์ ๋ง๋ค์ด์ฃผ๊ธฐ ์ํด CONNECT BY(๊ณ์ธต์ ์ฟผ๋ฆฌ)๋ฅผ ์ฌ์ฉํ์์ต๋๋ค.