반응형
GROUP BY 관련 정리 잘 되어있는 블로그 발견
WHERE은 그룹화 전 조건
HAVING은 그룹화 후 조건
LEFT JOIN : SELECT된 왼쪽 테이블을 기준으로 합침
쿼리문 설명
cte 테이블과ANIMAL_OUTS 테이블을 합쳐서 cte.hour과 count(ani.ANIMAL_ID) 열을 SELECT함
LEFT JOIN 이기 때문에 조건 ON에 해당하는 값이 0 혹은 NULL이더라도 cte.hour 값은 왼쪽 열에 나타나고 오른쪽 HOUR(ani.DATETIME) 값은 우측 열에 나타남.
LEFT JOIN과 JOIN으로 하는 경우 각각 실행결과 차이
참고자료
1. mysql date and time function doc
dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html
2. WITH RECURSIVE 구문
dev.mysql.com/doc/refman/8.0/en/with.html#common-table-expressions-recursive
반응형
'Language > SQL' 카테고리의 다른 글
[SQL 연습] 프로그래머스 테스트 KIT (JOIN) (0) | 2020.10.31 |
---|---|
[SQL 연습] 프로그래머스 테스트 KIT (IS NULL) (0) | 2020.10.31 |
[SQL 연습] 프로그래머스 테스트 KIT (SUM,MAX,MIN) (0) | 2020.10.27 |
[SQL 연습] 프로그래머스 테스트 KIT (SELECT) (0) | 2020.10.27 |
댓글