SQL변수
-
프로그래머스 - 입양 시각 구하기(2)_set @SQL 문제 2024. 1. 9. 16:00
입양 시각 구하기 (2) 보호소에서는 몇 시에 입양이 가장 활발하게 일어나는지 알아보려 합니다. 0시부터 23시까지, 각 시간대별로 입양이 몇 건이나 발생했는지 조회하는 SQL문을 작성해주세요. 이때 결과는 시간대 순으로 정렬해야 합니다 -- 코드를 입력하세요 # 변수를 지정 # HOUR는 1씩 증가해야 하므로 -1로 설정해서 0시도 나오게 한다. SET @HOUR := -1; SELECT (@HOUR := @HOUR +1) AS HOUR, ( SELECT COUNT(HOUR(DATETIME)) FROM ANIMAL_OUTS WHERE #우리가 만든 변수가 DATETIME이라는 조건 HOUR(DATETIME) = @HOUR ) AS COUNT FROM ANIMAL_OUTS WHERE #@HOUR가 22가..