Skip to content
Advertisement

Find out available days and slots for doctor appointment

I have three tables:

TimeSlotToken is the number of patients a doctor will see in his TimeSlot.
TimeSlot 1, 2, and 3 are Morning, Afternoon and Evening respectively.

I need to find the days where the TimeSlot is not full, i.e TimeSlot token is less than total bookings on that particular day and that slot. Since each doctor may have more than one time slot per day, I am having trouble. If all three TimeSlots are filled in a particular day, show me those unavailable dates (which I will use later). And find the TimeSlots and Dates of those days where timeslots are not filled.

To find the unavailable dates I am trying the code:

But this is not working. Please help!
P.S- Column names are not case sensitive. I have more complex names which I simplified here hence the difference..

Advertisement

Answer

Taking from comment to an answer for reference – as OP arrived at the same solution herself.

See it in action: SQL Fiddle.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement