[[PageOutline]] = MariaDB SEQUENCE 스토리지 엔진 = https://mariadb.com/kb/en/sequence-storage-engine/ 10.0 버전부터 지원. 잘 사용하면 커서를 사용하지 않고(반복 작업을 하지 않고) 성능을 향상시킬 수 있다. sequence 스토리지 엔진을 사용하려면 테이블 이름을 다음과 같이 지정해주면 된다. '''seq_FROM_to_TO''' 또는 '''seq_FROM_to_TO_step_STEP''' * FROM: 시작숫자 * TO: 끝 숫자 * STEP: 간격. 1일 때는 생략. 오름차순일 때는 FROM에서 시작한다. TO 이전에 끝날 수 있다. {{{ SELECT * FROM seq_1_to_15_step_3; +-----+ | seq | +-----+ | 1 | | 4 | | 7 | | 10 | | 13 | +-----+ }}} 내림차순일 때는 TO에서 끝난다. FROM에서 시작하지 않을 수 있다. {{{ SELECT * FROM seq_15_to_1_step_3; +-----+ | seq | +-----+ | 13 | | 10 | | 7 | | 4 | | 1 | +-----+ }}} == 응용 == 예 1. 40년 뒤까지 3월 14일이 무슨 요일인지 출력. {{{ SELECT DAYNAME('2008-03-14' + INTERVAL (seq) YEAR) as day, '2008-03-14' + INTERVAL (seq) YEAR as date FROM seq_0_to_40; }}} 예 2. 각 방별 상태값 출력. {{{ select transTime as '시각', case json_extract(json, concat('$.rooms[', n.seq - 1, '].roomNum')) when 1 then '거실' else concat('방 ', json_extract(json, concat('$.rooms[', n.seq - 1, '].roomNum')) - 1) end as '방', case json_extract(json, concat('$.rooms[', n.seq - 1, '].occupant')) when 0 then '비재실' when 1 then '재실' when 2 then '취침' end as '재실', json_extract(json, concat('$.rooms[', n.seq - 1, '].temperature')) as '온도', case when json_extract(json, concat('$.rooms[', n.seq - 1, '].mode')) is null or json_extract(json, concat('$.rooms[', n.seq - 1, '].mode')) = 1 then json_extract(json, concat('$.rooms[', n.seq -1, '].settingTemperature')) else null end as '설정 온도', case json_extract(json, concat('$.rooms[', n.seq - 1, '].mode')) when 0 then 'Off 모드' when 1 then '난방 모드' when 2 then '외출 모드' else json_extract(json, concat('$.rooms[', n.seq - 1, '].mode')) end as '설정 모드', case json_extract(json, concat('$.rooms[', n.seq - 1, '].lastSettingDevice')) when 0 then '사용자' when 1 then '앱' when 2 then '머신러닝' when 3 then '스케줄' end as '최종 설정 기기', json_extract(json, concat('$.rooms[', n.seq - 1, '].lastSettingTime')) as '최종 설정 시각', case json_extract(json, concat('$.rooms[', n.seq - 1, '].settingDevice')) when 0 then '사용자' when 1 then '앱' when 2 then '머신러닝' when 3 then '스케줄' end as '설정 기기', case json_extract(json, concat('$.rooms[', n.seq - 1, '].onOff')) when 0 then 'Off' when 1 then 'On' end as '밸브' from switch_trans_json s -- 실증 세대는 스위치 번호가 최대 5까지 있기 때문에 cross join seq_1_to_5 n where houseNum like 'SS-GRO2-DASANGNG-KCH%' and transTime >= '2020-12-19 00:00:00' and transTime < '2020-12-19 09:00:00' and json_extract(json, concat('$.rooms[', n.seq - 1, '].roomNum')) is not null order by 1; }}} ---- [WikiStart 처음으로]