Mysql:检查范围时间冲突 [英] Mysql: checking range time conflicts
本文介绍了Mysql:检查范围时间冲突的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有下面的表来存储教师类例程
I have the following table where teachers class routine are stored
表名:batchroutine_regular
Table Name: batchroutine_regular
batchid class_day subject teacherid class_start class_end
1 Sunday English-1 1001 02:00 PM 03:30 PM
1 Sunday Geography 1002 04:00 PM 05:30 PM
2 Monday Math 1001 10:00 AM 12:30 PM
2 Tuesday Geography 1001 01:00 PM 03:30 PM
现在假设你是 teacherid
是 1001
的老师。您将被要求在星期一参加课程,课程开始于 11:00 AM
,结束于 1:00 PM
。现在我的问题是什么是MYSQL / PHP查询,以查明,如果你在那时可用,从表 batchroutine_regular
?
Now lets say you are the teacher whose teacherid
is 1001
. You are asked to take a class on Monday which will start at 11:00 AM
and end at 1:00 PM
. Now my question is what would be the MYSQL/PHP query to find out if you are available at that time, from the table batchroutine_regular
?
感谢提前:)
推荐答案
SELECT (COUNT(*) = 0) AS Available
FROM batchroutine_regular
WHERE
teacherid = 1001
AND class_day = 'Sunday'
AND (
(class_start <= MAKETIME(11,00,00) AND class_end >= MAKETIME(11,00,00))
OR (class_start <= MAKETIME(13,00,00) AND class_end >= MAKETIME(13,00,00))
)
这篇关于Mysql:检查范围时间冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文