ich eine Reservierung Reservierungssystem zu schaffen, und ich versuche, eine Abfrage zu schreiben, die zu einem bestimmten Zeitpunkt frei, welche Ressourcen zeigt (ermöglicht es Benutzern, welche Stationen buchen zu wählen)Reservierungen SQL-Abfrage
Ich habe zwei Tabellen in meiner Datenbank
Erste Tabelle
|workstationid | location|
+--------------+---------+
| 1 |Downsview|
| 2 |Downsview|
| 3 |Downsview|
| 4 |Downsview|
| 5 |Downsview|
Zweite Tabelle
|wsid |location |email |duration |startDate |endDate |
+-----+------------+------------+---------+----------+--------+
| 1 | Downsview | randomemail| 5 | 9/4/2017 |9/8/2017|
Die Abfrage Ich Ausführung bin, ist
SELECT r.wsid,r.location FROM test_revision2 r WHERE r.location='Downsview' AND not exists(select 1 from test_bookings2 b WHERE r.wsid = b.wsid AND r.location = b.location AND b.startDate > '9/5/2017'AND b.endDate <'9/5/2017')
jedoch das Problem in der Abfrage ist, dass es alle fünf Standorte als verfügbar kehrt jedoch, wie Sie in meinem zweiten Tabelle sehen kann, gibt es eine Buchung von Sept4th -Sept 8 für Workstation 1.
Anregungen oder Hilfe wäre
workstationid location
1 Downsview
2 Downsview
3 Downsview
4 Downsview
5 Downsview
PSA: [ISO-Datumsformat] (https://xkcd.com/1179/). – HABO
Was ist das erwartete Ergebnis für das Datum '9/5/2017'? Arbeitsplatznummern 2,3,4,5? –
Ja, das ist richtig @OtoShavadze – rahulchawla