고양이와 개는 몇 마리 있을까
SELECT ANIMAL_TYPE,COUNT(*) FROM ANIMAL_INS
GROUP BY ANIMAL_TYPE ORDER BY ANIMAL_TYPE;
동명 동물 수 찾기
SELECT NAME, COUNT(NAME) FROM ANIMAL_INS
GROUP BY NAME HAVING COUNT(NAME)>1 ORDER BY NAME;
입양 시각 구하기(1)
SELECT HOUR(DATETIME) "HOUR",COUNT(*) "COUNT" FROM ANIMAL_OUTS
GROUP BY HOUR(DATETIME) HAVING HOUR BETWEEN 9 AND 20
ORDER BY HOUR(DATETIME);
입양 시각 구하기(2)
SET @HOUR := -1; -- =(비교연산자)와 차별하기 위한 :=(대입연산자)
SELECT (@HOUR:=@HOUR+1) "HOUR",
(SELECT COUNT(*) FROM ANIMAL_OUTS WHERE HOUR(DATETIME) = @HOUR) "COUNT"
FROM ANIMAL_OUTS WHERE @HOUR<23;