I have the below table INDISPONIBILITY, that respresents the availability of teachers, for example the teacher a1 is not available from 25-Jan-21 to 25-Jan-21 from 8:00 to 12:00.
I want to select teachers available in a givin date and hour. For example with a date 26-Jan-21 and hour 10:00 the teachers a1 and a2 are not available, but at 12:00 are available.
id endDate startDate startHour endHoure fk_teacher
1 25-Jan-21 25-Jan-21 800 1200 a1
2 25-Jan-21 25-Jan-21 1400 1600 a1
3 26-Jan-21 26-Jan-21 1000 1130 a1
4 29-Jan-21 28-Jan-21 1200 1400 a2
5 26-Jan-21 26-Jan-21 1000 1130 a2
I tried with this query, but in this date 26-Jan-21 and hour 10:00 it returns the teachers a1 and a2.
public static String query = "SELECT * FROM ESP_ENSEIGNANT s \n" +
" LEFT JOIN INDISPONIBILITY ds ON ds.fk_teacher = s.teacherId\n" +
" WHERE (?1 NOT BETWEEN ds.STARTDATE AND ds.ENDDATE) AND (?2 NOT BETWEEN ds.startHour AND ds.endHour)";
@Query(nativeQuery = true, value = query)
List<TeacherEntity> findAllByUps(Date effectDate, int hour);