[Level2] GROUP BY




고양이와 개는 몇 마리 있을까

programmers


    SELECT ANIMAL_TYPE, COUNT(ANIMAL_ID) AS 'count'
      FROM ANIMAL_INS
  GROUP BY ANIMAL_TYPE
  ORDER BY ANIMAL_TYPE


동명 동물 수 찾기

programmers


  SELECT NAME, COUNT(ANIMAL_ID) AS 'COUNT'
    FROM ANIMAL_INS
   WHERE NAME IS NOT NULL
GROUP BY NAME
  HAVING COUNT >= 2
ORDER BY NAME


입양 시각 구하기(1)

programmers


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