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

gov's avatar
Dec 26, 2024
고양이와 개는 몇 마리 있을까
Contents
문제풀이

문제

notion image

풀이

SELECT animal_type, count(*) as count from animal_ins group by animal_type order by animal_type;
  • GROUP BY animal_type
    • GROUP BY : 데이터를 그룹화하여 집계
    • animal_ins 테이블에서 동물의 종류(animal_type)별로 같은 종류의 동물들을 묶어서 각 종류별 개수 세기
  • ORDER BY animal_type
    • ORDER BY : 결과를 정렬
    • animal_type을 기준으로 결과를 오름차순(기본값)으로 정렬. 즉, 동물 종류(animal_type)가 알파벳 순으로 정렬
 
Share article

goho