반응형
https://programmers.co.kr/learn/courses/30/lessons/59413
배운것: RECURSIVE, DATE_FORMAT
WITH RECURSIVE TEMP AS(
##NON_RECURSIVE
SELECT 0 AS HOUR
UNION ALL
## RECURSIVE
SELECT HOUR+1 FROM TEMP
WHERE HOUR < 23
)
SELECT HOUR, COUNT(ANIMAL_ID) AS COUNT
FROM ANIMAL_OUTS AS A
RIGHT JOIN TEMP AS H
ON HOUR = DATE_FORMAT(A.DATETIME, "%H")
GROUP BY HOUR
ORDER BY HOUR
댓글