use sipstats; alter table statistics remove partitioning; set @stm = concat('alter table statistics partition by range (floor(timestamp)) (partition p_old values less than (', coalesce((select floor(max(timestamp)) from statistics), 0) + 600, '))'); prepare st from @stm; execute st; deallocate prepare st;