在 MySQL 中查找可用的时间范围 [英] Find an available time frame in MySQL
本文介绍了在 MySQL 中查找可用的时间范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图找出从 UNIX 开始到 UNIX 结束的时间范围是否可用.我有如下数据:
I am trying to find if a time frame is availability from UNIX start to UNIX end. I have data like:
id start end
1 1309383000 1309390200
2 1305115200 1305129600
3 1305374400 1305403200
我正在尝试在给定开始和结束的地方运行查询,并检查是否采取了这种缓慢措施.但是,start
可以在另一个条目结束时开始.我尝试了很多不同的方法,但无法正常工作.任何帮助表示赞赏.
I am trying to run a query where I have a given start and end, and checking to see if this slow is taken. However, a start
can start when another entry ends. I have tried a lot of different ways, cannot get it to work right. Any help is appreciated.
我正在使用 PHP 来调用查询.但是,如果可能,我想在纯 MySQL 中进行.
I am using PHP to call the query. However, I would like to do it in pure MySQL if possible.
推荐答案
select if(max(end) >= $end, max(end), $end) -
if(min(start) <= $start, min(start), $start) -
if(sum(end - start) is null, 0, sum(end - start)) as FreeTime
where end > $start and start < $end
这篇关于在 MySQL 中查找可用的时间范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文