如何获得最小的免费约会

时间:2014-05-15 08:03:57

标签: mysql sql

我有带有属性时间的mysql表记录,我想在指定的时间内插入新记录,但是如果有其他记录同时,我需要将新的记录时间转换为指定的时间间隔,直到没有相同的记录时间。
所以我需要sql查询,它从指定的时间找到最小的空闲时间,这是指定时间间隔的n次移位。
例如,如果存在时间为1,2,4,5,7的记录和时间为2且时间间隔为2的新记录,则查询将返回6.

1 个答案:

答案 0 :(得分:0)

您需要一个存储所有可能时间的表格。然后左边用all_times加入times表,找到一条记录,其中actual_time匹配为空。

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>:desiredTimeParameter
相关问题