728x90

일정시간이 경과한 데이터는 삭제처리하는 로직을 만들기 위해서 구현해 본 쿼리다.

 

# 2시간 이내에 있는 데이터만 추출

select idx,userID,access_date from accessLog where access_date > subtime(current_timestamp(), '2:0:0') and access_date < current_timestamp();

 

# 2시간 경과한 데이터만 추출

select idx,userID,access_date from accessLog where access_date < subtime(current_timestamp(), '2:0:0');

 

# 2시간 경과한 데이터 삭제

delete from accessLog where access_date < subtime(current_timestamp(), '2:0:0');

 

 

 

 

'SQL' 카테고리의 다른 글

접속로그 통계 (신규, 중복 동시 처리)  (0) 2023.05.23
MySQL foreign key 예제  (0) 2022.05.16
[MySQL] 샘플 데이터베이스 설치하기  (0) 2022.04.28
MariaDB 멀티 인덱스(index) 설정  (0) 2022.04.05
MariaDB 대소문자 구분  (0) 2022.03.14
블로그 이미지

Link2Me

,