BackEND/Database 9

mysql substring_index 사용

mysql substring_index 사용법을 알아보자. 문자열 str 을 delim 로 구분해서 배열로 만든 후 count 만큼만 보여준다. count 가 양수이면 왼쪽에서 count 수만큼 보여주고 음수이면 오른쪽에서 count 수 만큼 보여준다. mysql> select substring_index('www.mysql.com', '.', 2);-> 'www.mysql' mysql> select substring_index('www.mysql.com', '.', -2);**substring_index 사용법 -> 'mysql.com' ex) SUBSTRING_INDEX(DeptName, '-', -2) AS dept :::: ㅁㅁㅁ-ㄴㄴㄴ-ㅇㅇㅇ-ㄹㄹㄹ----> ㅇㅇㅇ-ㄹㄹㄹ

BackEND/Database 2017.11.30

mysql IP 정렬 - INET_ATON

mysql 에서 IP를 조회할 때, 일반적인 ORDER BY 정렬로는 아마 아래와 같이 조회될 것이다. 실행 : SELECT * FROM ip_addresses ORDER BY ip_address; 결과 :| ip_address |+--------------+| 192.168.1.1 || 192.168.1.13 || 192.168.1.2 || 192.168.1.22 || 192.168.1.3 | 이럴땐 ORDER BY 에 INET_ATON 함수를 쓰도록 하자. 실행 : SELECT * FROM ip_addresses ORDER BY INET_ATON(ip_address); 결과 : | ip_address |+--------------+| 192.168.1.1 || 192.168.1.2 || 192.168..

BackEND/Database 2017.11.30

mysql GROUP_CONCAT 활용 및 max 사이즈 변경

1. max 사이즈 조회SELECT @@group_concat_max_len 2. max 사이즈 변경SET @@group_concat_max_len = 1000000; 예) SELECT a.vehicle_seq, a.license_plate, GROUP_CONCAT(a.start_date ORDER BY a.start_date) start_date, GROUP_CONCAT(a.result_value ORDER BY a.start_date) result_value, LENGTH(GROUP_CONCAT(a.start_date ORDER BY a.start_date)) start_date_length, LENGTH(GROUP_CONCAT(a.result_value ORDER BY a.start_date)) r..

BackEND/Database 2017.11.30