Delete records in a period of time, the key is to delete the filter criteria to determine when to delete range

Copyright: quack https://blog.csdn.net/qq_41570658/article/details/91446871

Delete records in the period of time when the key is determined to delete filters deletion range, preferably in the data table has a field representing the time, which time is determined according to the condition field in the time period, and then delete

 

Error Demo:

   DELETE FROM tb t WHERE t.time <='2019-06-06 00:00:00';

1, using the keywords BETWEEN delete records within a certain time according to the time field

1

DELETE FROM 表名 WHERE 时间字段 BETWEEN 开始时间 AND 结束时间

Example:

1

2

DELETE FROM tb WHERE CreateTime BETWEEN '2017-01-01 00:00:00' AND '2017-02-01 00:00:00'

--删除tb表中2017年1月1日到2017年2月1日的数据

2, with a time field to determine the size comparison deletion range

1

2

--语法:

DELETE FROM 表名 WHERE 时间字段>=开始时间 AND 时间字段<=结束时间

Example:

1

DELETE FROM tb WHERE CreateTime>='2017-01-01 00:00:00' AND CreateTime<='2017-02-01 00:00:00'

Guess you like

Origin blog.csdn.net/qq_41570658/article/details/91446871