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

 

프로그래머스

SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프

programmers.co.kr

 

재귀 쿼리를 이용해서 0~23시를 구해줘야 하는 문제이다.

count 함수 인자에 특정 속성값을 넣을 경우 null인 경우는 제외하므로 * 대신 특정 속성값을 넣어줘야 한다.

 

with recursive h as (
	select 0 as n
    union all
    select n+1 as n
    from h
    where n<23
)

select a.n, count(b.animal_id) as count
from h a left join animal_outs b
on a.n = hour(b.datetime)
group by a.n

+ Recent posts