我有如下的日程安排数据课程,我怎么能检测到它上面有任何数据冲突/冲突数据?在mysql语法
+-----------+--------+--------+---------+-----------+----------+---------+--------+-------+
| IDCourse | Day | Class | Room | IDTeacher | Capacity | Residue | Begin | End |
+-----------+--------+--------+---------+-----------+----------+---------+--------+-------+
| MI09BB11 | Monday | A | A.1.4 | RA | 40 | 1 | 08:00 | 10:00 |
| MI09BB12 | Monday | A | A.1.4 | RA | 40 | 1 | 08:30 | 10:30 | <-- clash
| MI09BB51 | Monday | A | A.1.4 | RA | 40 | 1 | 11:00 | 13:00 |
-
-
-
+-----------+--------+--------+---------+-----------+----------+---------+--------+-------+
抱歉我的英语不好。感谢
答案 0 :(得分:0)
假设我正确理解你的问题,你是否正在寻找时间范围与其他条目重叠的行?
如果是这样,你可以像这样比较你的时间:
SELECT T2.IDCourse, T2.Begin, T2.End
FROM YourTable T
INNER JOIN YourTable T2 ON
T.Day = T2.Day AND
T.Begin <= T2.End AND
T.End >= T2.Begin
JOIN
或WHERE
条件:
WHERE T.PrimaryKey <> T2.PrimaryKey
答案 1 :(得分:0)
SELECT s1.IDCourse, s2.IDCourse, s1.Day
FROM schedule s1
JOIN schedule s2
ON s1.Day = s2.Day AND s1.Room = s2.Room AND s1.IDCourse != s2.IDCourse
WHERE s1.Begin BETWEEN s2.Begin AND s2.End