Skip to content

Tag: date-range

MySQL- Find records with overlapping period

I have a table hotel_booking reference start_date numberOfDays ABC 11-08-2021 2 DEF 12-08-2021 2 GHI 13-08-2021 3 JKL 10-08-2021 2 So the first task I wanted was to get all bookings which has startDate between x and y date which is straight forward query This returns me ABC and DEF which is perfect. Now I wan…

Generate a range of records depending on from-to dates

I have a table of records like this: Item From To A 2018-01-03 2018-03-16 B 2021-05-25 2021-11-10 The output of select should look like: Item Month Year A 01 2018 A 02 2018 A 03 2018 B 05 2021 B 06 2021 B 07 2021 B 08 2021 Also the range should not exceed the current month. In example above

insert extra rows in query result sql

Given a table with entries at irregular time stamps, “breaks” must be inserted at regular 5 min intervals ( the data associated can / will be NULL ). I was thinking of getting the start time, making a subquery that has a window function and adds 5 min intervals to the start time – but I only…

Postgres Left Join with where condition

I need to left join two tables with a where condition: time_table record_table I need to get all those records which are present under given date range. In the above example, I need those records that lie under range for rid = 2 only. Hence the output for the above query needs to be: Answer left join two tabl…