1 回答
TA贡献1757条经验 获得超7个赞
我认为你采取了错误的方式,对我来说这是一个否定的检查,如果它给你带来超过 0 行,它将失败:
是否有任何课程在同一地点同时进行?
或者我的老师是否应该同时开设任何其他课程?
如您所见,OR您的查询中有一个 I can't find 。(我不明白你Event_id的意思,所以我可能会在这里错过任何东西)
在制品
这部分至少可以回答你问题的一大部分,告诉我什么仍然不适合你。
查询 1:
SET -- this is your input you try to check
@local_id = 1,
@heure_debut = '08:00',
@heure_fin = '09:00',
@enseignant_id = 1
结果:
查询 2:
-- if it return more that 0 record, then you have a conflict
SELECT
r.id AS id_line_in_conflict
, r.* -- for debug
FROM `reservations` r
WHERE
heure_debut < @heure_fin
AND heure_fin > @heure_debut
AND (
local_id = @local_id -- check if the local is empty
OR enseignant_id = @enseignant_id -- check if the teacher is free
)
结果:
| id_line_in_conflict | id | numero_semaine | date | heure_debut | heure_fin | Event_id | horaire_id | local_id | enseignant_id |
|---------------------|----|----------------|----------------------|-------------|-----------|----------|------------|----------|---------------|
| 1 | 1 | 16 | 2020-04-17T00:00:00Z | 08:00 | 12:00 | 1 | 4 | 1 | 1 |
| 2 | 2 | 16 | 2020-04-17T00:00:00Z | 08:00 | 09:00 | 1 | 4 | 2 | 1 |
查询 3:
SET -- this is your input you try to check
@local_id = 1,
@heure_debut = '14:00',
@heure_fin = '15:00',
@enseignant_id = 3
结果:
查询 4:
-- if it return more that 0 record, then you have a conflict
SELECT
r.id AS id_line_in_conflict
, r.* -- for debug
FROM `reservations` r
WHERE
heure_debut < @heure_fin
AND heure_fin > @heure_debut
AND (
local_id = @local_id -- check if the local is empty
OR enseignant_id = @enseignant_id -- check if the teacher is free
)
结果:
- 1 回答
- 0 关注
- 153 浏览
添加回答
举报
