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

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr


구해야 할 것을 나누어보면

1) 09:00~19:59까지의 시간만 골라낼 것

2) 시간대별로 구분해서 count할 것

3) 시간대 순으로 정렬할 것

이다.

 

1)은 where문을 이용해서 쉽게 구해보았다.

2)는 datetime 형식은 hour()를 이용하면 저장된 시만 알 수 있다.

그 후 그룹화하여 묶는 group by를 이용하여 나누어 저장한다.

3)은 order by 이용.

SELECT hour(datetime), count(animal_id) from animal_outs 
where hour(datetime)>=9 and hour(datetime)<=19 
group by hour(datetime) order by hour(datetime) ;

+ Recent posts