[SQL문제풀기] 고양이와 개는 몇 마리 있을까(GROUP BY)

241203
이나겸's avatar
Dec 02, 2024
[SQL문제풀기] 고양이와 개는 몇 마리 있을까(GROUP BY)
Contents
Q.풀이

Q.

notion image
 
 

풀이

  • where animal_type in ('Cat', 'Dog')
    • Cat과 Dog에 해당하는 데이터만 필터링
  • group by
    • 그룹화
  • order by animal_type = 'Cat' desc
    • Cat이 Dog보다 먼저 출력되도록 정렬
select animal_type, count(*) as count from animal_ins where animal_type in ('Cat', 'Dog') group by animal_type order by animal_type = 'Cat' desc;
Share article

Nakyeom's Study