2

我有下表存储教师课堂例程

表名: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

提前致谢 :)

4

1 回答 1

4
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))
  )
于 2012-04-24T12:14:09.313 回答