고양이와 개는 몇 마리 있을까
https://programmers.co.kr/learn/courses/30/lessons/59040
SELECT ANIMAL_TYPE, COUNT(*) AS count
FROM ANIMAL_INS
GROUP BY ANIMAL_TYPE
ORDER BY ANIMAL_TYPE;
동명 동물 수 찾기
https://programmers.co.kr/learn/courses/30/lessons/59041
SELECT NAME, COUNT(NAME) AS COUNT
FROM ANIMAL_INS
GROUP BY NAME
HAVING COUNT(NAME) > 1
ORDER BY NAME ASC;
입양 시각 구하기(1)
https://programmers.co.kr/learn/courses/30/lessons/59412
SELECT HOUR(DATETIME) AS HOUR, COUNT(DATETIME) AS COUNT
FROM ANIMAL_OUTS
WHERE HOUR(DATETIME) >= 9 AND HOUR(DATETIME) < 20
GROUP BY HOUR
ORDER BY HOUR;
-- 코드2
SELECT HOUR(DATETIME) AS 'HOUR', COUNT(HOUR(DATETIME)) AS 'COUNT'
FROM ANIMAL_OUTS
WHERE HOUR(DATETIME) >= 9 AND HOUR(DATETIME) < 20
GROUP BY HOUR(DATETIME)
ORDER BY HOUR(DATETIME);
입양 시각 구하기(2)
https://programmers.co.kr/learn/courses/30/lessons/59413
-- 교수님 코드 (코드 참조)
-- 추후 다시 도전할것
SET @hour := -1;
# 변수선언 0으로 맞추기위해
SELECT (@hour := @hour + 1) as HOUR,
# 반복하면서 식별자안에 0~23을 할당
(SELECT COUNT(*) FROM ANIMAL_OUTS WHERE HOUR(DATETIME) = @hour) as
COUNTFROM ANIMAL_OUTSWHERE @hour < 23;
'PS (Problem Solving) > Programmers' 카테고리의 다른 글
[프로그래머스] 신규 아이디 추천 (0) | 2022.07.28 |
---|---|
[프로그래머스] 신고 결과 받기 - 파이썬 (0) | 2022.07.27 |
[프로그래머스] SQL 고득점 Kit - IS NULL (0) | 2022.04.19 |
[프로그래머스] SQL 고득점 Kit - SUM, MAX, MIN (0) | 2022.04.19 |
[프로그래머스] SQL 고득점 Kit - SELECT (0) | 2022.04.19 |