GROUP BY 관련 정리 잘 되어있는 블로그 발견
[MySQL] 그룹화하여 데이터 조회 (GROUP BY)
▶MySQL 그룹화하여 데이터 조회 (GROUP BY) ▶설명 하나, 예를 들어보겠습니다. MySQL에서 유형별로 갯수를 가져오고 싶은데, 단순히 COUNT 함수로 데이터를 조회하면 전체 갯수만을 가져옵니다. 이렇
extbrain.tistory.com
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
MySQL :: MySQL 8.0 Reference Manual :: 12.7 Date and Time Functions
12.7 Date and Time Functions This section describes the functions that can be used to manipulate temporal values. See Section 11.2, “Date and Time Data Types”, for a description of the range of values each date and time type has and the valid formats
dev.mysql.com
2. WITH RECURSIVE 구문
dev.mysql.com/doc/refman/8.0/en/with.html#common-table-expressions-recursive
MySQL :: MySQL 8.0 Reference Manual :: 13.2.15 WITH (Common Table Expressions)
13.2.15 WITH (Common Table Expressions) A common table expression (CTE) is a named temporary result set that exists within the scope of a single statement and that can be referred to later within that statement, possibly multiple times. The following disc
dev.mysql.com
'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 |
댓글