now is better than never

[Level 4][GROUP BY] 입양시각 구하기 (2) ([Oracle] 0에서 23 까지 숫자 생성) 본문

프로그래머스/SQL

[Level 4][GROUP BY] 입양시각 구하기 (2) ([Oracle] 0에서 23 까지 숫자 생성)

김초송 2023. 1. 3. 16:41

https://school.programmers.co.kr/learn/courses/30/lessons/59413 

 

MySQL로도 풀어보고 싶었으나 실패

 

<Oracle>

select h.hour, nvl(ao.count,0) count
from
        (select level-1 as hour
        from dual
        connect by level <=24) h
    left join
        (select to_number(to_char(datetime, 'HH24')) hour, count(*) count
        from animal_outs
        group by to_number(to_char(datetime, 'HH24')) ) ao
    on h.hour = ao.hour
order by h.hour;