문제출처 프로그래머스
SQL 고득점 키트 - GROUP BY
SELECT ANIMAL_TYPE, COUNT(ANIMAL_TYPE)
FROM ANIMAL_INS
GRUOP BY ANIMAL_TYPE
ORDER BY ANIMAL_TYPE
SELECT NAME, COUNT(NAME)
FROM ANIMAL_INS
GROUP BY NAME HAVING COUNT(NAME) > 1
ORDER BY NAME;
SELECT HOUR(DATETIME) HOUR, COUNT(DATETIME) COUNT
FROM ANIMAL_OUTS
GROUP BY HOUR(DATETIME)
HAVING HOUR >= 9 and HOUR <=19
ORDER BY HOUR(DATETIME)
SET @hour := -1;
SELECT (@hour := @hour + 1) as HOUR,
(SELECT COUNT(*) FROM ANIMAL_OUTS
WHERE HOUR(DATETIME) = @hour) as COUNT
FROM ANIMAL_OUTS
WHERE @hour < 23