본문 바로가기

Database/Mysql

(3)
[MYSQL] 프로그래머스 - 경기도에 위치한 식품창고 목록 출력하기 문제  핵심1. 쿼리에서 if문 사용하기  1. if문 사용if(조건, 참일 때, 거짓일 때) 예시select fw.id, if(fw.is_free is null, 'N', fw.is_free) as is_freefrom ~  정답select fw.warehouse_id, fw.warehouse_name, fw.address, if(fw.freezer_yn is null, 'N', fw.freezer_yn) as freezer_ynfrom food_warehouse fwwhere fw.address like '경기도%'order by fw.warehouse_id asc
[TS] this is incompatible with sql_mode=only_full_group_by 해결 방법 본 포스팅은 Mysql에서 group by 절을 사용하다가 발생한 에러에 대한 기록이다.  발생한 에러Error 1055: Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'a.author_name' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_byError 1055: Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'a...
[MYSQL] 프로그래머스 - 서울에 위치한 식당 목록 출력하기 문제  테이블 관계일대다(1:N) 관계의 테이블식당 : 식당 리뷰 = 1 : N핵심1. 리뷰 평균 점수2. 소숫점 세 번째 자리에서 반올림3. 정렬: 첫 번째 기준으로 정렬, 단 첫 번째 기준이 같다면 두 번째 기준으로 정렬 1. 평균 점수select avg(식당_리뷰.점수)from 식당join 식당_리뷰 on 식당.id = 식당_리뷰.식당_idgroup by 식당id 2. 소숫점 세 번째 자리에서 반올림select round(식당_리뷰.점수, 2)from 식당_리뷰 3. 정렬: 첫 번째 기준으로 정렬, 단 첫 번째 기준이 같다면 두 번째 기준으로 정렬select *from 식당_리뷰order by 첫 번째 기준, 두 번째 기준  * 주의할 점기준 컬럼의 순서가 어플리케이션에서 정렬하는 것과 차이가 있다..