1 回答

TA貢獻(xiàn)1757條經(jīng)驗(yàn) 獲得超7個(gè)贊
我認(rèn)為你采取了錯(cuò)誤的方式,對我來說這是一個(gè)否定的檢查,如果它給你帶來超過 0 行,它將失敗:
是否有任何課程在同一地點(diǎn)同時(shí)進(jìn)行?
或者我的老師是否應(yīng)該同時(shí)開設(shè)任何其他課程?
如您所見,OR您的查詢中有一個(gè) I can't find 。(我不明白你Event_id的意思,所以我可能會(huì)在這里錯(cuò)過任何東西)
在制品
這部分至少可以回答你問題的一大部分,告訴我什么仍然不適合你。
查詢 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 關(guān)注
- 76 瀏覽
添加回答
舉報(bào)