//--------------------------------------
* GROUP BY 쿼리 에러  
Expression  of SELECT list is not in GROUP BY clause and contains nonaggregated column  which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by 
- 원인  
http://jason-heo.github.io/mysql/2014/03/05/char13-mysql-group-by-usage.html 
GROUP BY를 사용하는 경우, SELECT할 수 있는 컬럼은 GROUP BY에 나열된 컬럼과 SUM(), COUNT() 같은 집계 함수(Aggregation Function)으로 한정 
sql 표준 문법은 group by 사용시 select 의 칼럼중 집계함수에 쓰이는 것을 제외한 모든 칼럼을 기입해야 한다. 
//-------------- 
- 해결 방법 1 - 쿼리 변경, group by 에 모두 기입 
select col1, col2,  count(col3) from table1 
group by col1, col2;  # 집계함수 이외의 모든 select 칼럼을 기입 
- 해결 방법 2 - 쿼리 변경 ,   비 집계 칼럼에 ANY_VALUE() 함수 사용 
select col1, ANY_VALUE(col2),  count(col3) from table1 
group by col1; 
- 해결 방법 3 - mysql 설정 변경 
sql_mode 에서 ONLY_FULL_GROUP_BY 설정을 뺀다 
SET SESSION sql_mode = 'NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES';
- 설정파일(my.cnf)에서 ONLY_FULL_GROUP_BY 를 찾아 삭제한다.
'Code > Database (DB)' 카테고리의 다른 글
| [펌] MySQL 8.0 새기능 (0) | 2020.03.10 | 
|---|---|
| [MySql] Explain (0) | 2020.03.08 | 
| [MySql] sql_mode 설정 (0) | 2020.03.02 | 
| mysql DB 복원시 경고 메시지 해결 방법 (1) | 2020.02.25 | 
| [MySql] DB 서버 최적화 명령 (Optimize, Analyze Table) (0) | 2020.02.25 | 










