create table t (n int);
insert into t values (1);
insert into t select * from t; -- 이걸 13번 반복하면 4096행이 생성됨. 10년치 데이터라면 대략 3650일이므로 이정도면 충분
create table date_t (d date, ds char(8)); -- 날짜를 저장할 테이블
insert into date_t
select d, date_format(d, '%Y%m%d') from (
select @rnum:=@rnum+1 as rownum, date(adddate('2009-01-01', interval @rnum day)) as d
from (select @rnum:=-1) r, t
) t
where year(d) < 2019;
참고로, 날짜는 date 타입에 저장하는 것이 yyyymmdd형식의 문자열로 저장하는 것보다 좋습니다
insert into high_block (stay_code , room_code , r_block , chk_date )
SELECT 'high01' , '1001' , 0 , date_format(d, '%Y-%m-%d') from (
select @rnum:=@rnum+1 as rownum, date(adddate('2019-01-01', interval @rnum day)) as d
from (select @rnum:=-1) r, t
) t
where year(d) < 2021;
은근 많이 쓰는거
'MySQL' 카테고리의 다른 글
마리아 DB 내부쿼리에서 order (0) | 2019.10.16 |
---|---|
character 한번에 바꾸기 (0) | 2019.10.16 |
MySQL IFNULL (0) | 2012.12.03 |
테이블 내 특정 문자열 한꺼번에 바꾸기 - REPLACE (0) | 2012.08.30 |
MySQL / FullText에서 특정 단어를 빠르게 검색하기 (0) | 2012.08.30 |