컴공생의 다이어리

[프로그래머스] 입양 시각 구하기(1) - MySQL 본문

Development/Algorithm & Coding Test

[프로그래머스] 입양 시각 구하기(1) - MySQL

컴공 K 2022. 4. 12. 00:01

[프로그래머스] 입양 시각 구하기(1) - MySQL

 

 

GROUP BY의 HAVING 활용
SELECT HOUR(DATETIME) AS HOUR, COUNT(DATETIME) AS COUNT FROM ANIMAL_OUTS 
GROUP BY HOUR(DATETIME) HAVING HOUR >=9 AND HOUR <=19 
ORDER BY HOUR;

# or

SELECT HOUR(DATETIME) AS HOUR, COUNT(DATETIME) AS COUNT FROM ANIMAL_OUTS 
GROUP BY HOUR(DATETIME) HAVING HOUR BETWEEN 9 AND 19 
ORDER BY HOUR;

 

 

WHERE 활용
SELECT HOUR(DATETIME) AS HOUR, COUNT(DATETIME) AS COUNT FROM ANIMAL_OUTS 
WHERE HOUR(DATETIME) >=9 AND HOUR(DATETIME) <=19 
GROUP BY HOUR(DATETIME) 
ORDER BY HOUR;

# or

SELECT HOUR(DATETIME) AS HOUR, COUNT(DATETIME) AS COUNT FROM ANIMAL_OUTS 
WHERE HOUR(DATETIME) BETWEEN 9 AND 19 
GROUP BY HOUR(DATETIME) 
ORDER BY HOUR;

 

 

 

 

 

 

 

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

 

코딩테스트 연습 - 입양 시각 구하기(1)

ANIMAL_OUTS 테이블은 동물 보호소에서 입양 보낸 동물의 정보를 담은 테이블입니다. ANIMAL_OUTS 테이블 구조는 다음과 같으며, ANIMAL_ID, ANIMAL_TYPE, DATETIME, NAME, SEX_UPON_OUTCOME는 각각 동물의 아이디, 생물

programmers.co.kr

 

728x90
반응형
Comments