问题描述
所以我想我大概首先通过在时间戳列上使用MIN函数来选择最早的时间戳。
,然后计算该值与current_timestamp之间经过的天数。
是否有一个统一的sql语句来执行此操作(经过的天数,而不是截断时间)
解决方法
在ANSI SQL中为:
select current_timestamp - min(the_timestamp_column)
from the_table;
这将返回一个interval
值。
要删除x天之前的行,可以将DELETE语句与相应的WHERE子句一起使用:
delete from the_table
where the_timestamp_column < current_timestamp - interval '42' day;