我有带时间属性的mysql表记录,想要在指定时间插入新记录,但如果有其他记录时间相同,则需要将新记录时间移位指定时间间隔,直到同时没有记录。
所以我需要sql查询,它可以找到指定时间的最小空闲时间,这是指定时间间隔的n时移。
例如,如果有时间为1、2、4、5、7的记录,而新记录的时间为2、间隔为2,则查询将返回6。
发布于 2014-05-15 16:17:02
您需要一个表来存储所有可能的时间。然后将times表与all_times连接起来,找到actual_time match为null的记录。
select min(at.time) as desired_free_time_value
from all_times at
left join times t on at.time=t.time
where t.time is null
and at.time>:desiredTimeParameterhttps://stackoverflow.com/questions/23672499
复制相似问题