본문 바로가기
728x90
반응형

Programming/MySQL12

auto_increment initialization (초기화) auto_increment를 이용하여 DB에 데이터를 쌓다보면 auto_increment가 어마어마하게 쌓여있는걸 볼수 있다. tabel을 초기화할 경우 auto_increment도 초기화를 해야 할 경우가 있다. alter table '테이블명' auto_increment = 1 위의 sql문을 이용하여 auto_increment를 초기화 하고 사용하면 된다. 2015. 6. 30.
[MySQL] 컬럼 & 필드 합치기 concat(), group_concat() concat() ex ) concat(column, column) item_table​idx category1category2 category3 5 1 2 3 select idx, concat(category1, "/", category2, "/", category3) as merge_column from item_table where idx = 5 idx merge_column 5 1/2/3 group_concat() ex) group_concat(field saparator '구분자') item_table idx category 5 1 5 2 5 3 select idx, group_concat(category saparator '/') as group_concatfrom item_tablewhere .. 2015. 6. 30.
[MySQL] 문자 치환하기 REPLACE() REPLACE(field, '수정 전', '수정 후'); ex)update 테이블 set 컬럼=replace(컬럼 ,'수정 전','수정 후');update coordi_type_table set coordi_type=replace(coordi_type, 'a' , 'b' ); coordi_type_table coordi_type (치환 전) coordi_type(치환 후) a b 2015. 6. 30.
몇 년치 날짜데이터 테이블 만들기 1. 날짜테이블을 생성하기 위한 더미 테이블 생성 create table t (n int); insert into t values (1); // 입력할 년도의 날짜 수만큼 행을 생성한다. insert into t select * from t 2. 날짜테이블 생성 create table date_t (d date, ds char(8)); insert into date_tselect d, date_format(d, '%Y%m%d') from ( select @rnum:=@rnum+1 as rownum, date(adddate('2014-01-01', interval @rnum day)) as d from (select @rnum:=-1) r, t ) twhere year(d) < 2024; [출처] http.. 2015. 6. 30.
728x90
반응형