습관처럼

programmers [SQL] : GROUP BY 본문

Algorithms/programmers

programmers [SQL] : GROUP BY

dev.wookii 2020. 5. 22. 13:05

programmers.co.kr/learn/courses/30/parts/17044

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

1. 고양이와 개는 몇마리나 있을까?

-- 코드를 입력하세요
SELECT animal_type, count(*)
from animal_ins
group by animal_type

2. 동명 동물 수 찾기

 

-- 코드를 입력하세요
SELECT name, count(*)
from animal_ins
group by name
having count(name)>1

3. 입양 시간 구하기(1)

-- 코드를 입력하세요
SELECT hour(datetime),count(*)
from animal_outs
where hour(datetime) between 9 and 19
group by hour(datetime)

4. 입양 시간 구하기(2)

set @time := -1;
select (@time := @time +1)as 'hour', (select count(*)
                                   from animal_outs
                                    where hour(datetime)=@time)as 'count'
from animal_outs
where @time<23

funny SQL~