I would like a query that would return the count of records that have their start-end time in specific time interval (eg. 30 mins).

For example records:


would result in

10:00-10:30|2x (records 1 and 3)
10:30-11:00|3x (all)
11:00-11:30|2x (records 1 and 2)
11:30-12:00|2x (records 1 and 2)
12:00-12:30|1x (record 2)

Usage: If I have for example 3 private instructors; I can't have more than 3 clients, meaning (in the example above) I can't appoint anybody from 10:30-11:00 as all 3 instructors are already occupied.

  • Welcome to our site! Could you please show what you already achieved and where you are stuck? – dezso Mar 13 '18 at 12:58
  • 1
    Always declare your version of Postgres, and it's always helpful to disclose the exact table definition with (CREATE TABLE statement). Also, be precise. in specific time interval does not clarify how to handle lower and upper interval bounds exactly. – Erwin Brandstetter Mar 13 '18 at 13:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.