1

我有像下面这样的计划数据课程,我怎么能检测到它上面是否有任何数据冲突/冲突数据?在 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 |
-
-
-
+-----------+--------+--------+---------+-----------+----------+---------+--------+-------+

对不起我的英语不好。谢谢

4

2 回答 2

1

假设我正确理解了您的问题,您正在寻找时间范围与其他条目重叠的行?

如果是这样,您可以像这样比较您的时间:

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

编辑:正如@Barmar 适当指出的那样,这将产生与自身冲突的结果。你有这张表的主键吗?将它(或您的唯一标识符)添加到您的JOINorWHERE标准中:

WHERE T.PrimaryKey <> T2.PrimaryKey
于 2013-07-15T04:00:22.570 回答
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
于 2013-07-15T04:02:36.313 回答