• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: Join with overlapping times using sql?

Resolved: Join with overlapping times using sql?

0
By Isaac Tonny on 17/06/2022 Issue
Share
Facebook Twitter LinkedIn

Question:

I have 2 tables, TABLE1:
and a TABLE2:
The issue is on the first table. Due to the overlap of start and end times, I need to be able to distinguish between whether there is an overlap. If there is an overlap, then I need to identify the category as “MULTIPLE”. If there isn’t an overlap, then I only flag the category as. the job_type. When joining to second table, the second table needs to have the job_type populated such that it will either show the one job_type if the time_sample from TABLE2 only falls between the start and end times of only 1 record from TABLE1. if the time_sample falls within more than 1 start/end times for that one job, then it should populate MULTIPLE. I’m having a hard time understanding how to be able to perform this kind of semi-aggregation/join logic to create the following:
The join should be on ‘job’ and where TABLE2.time_sample is between TABLE1.start_time and TABLE1.end_time

Answer:

You can do a simple join between the tables. For the job type check if there are multiple matches:
See db-fiddle

If you have better answer, please add a comment about this, thank you!

join mysql presto sql
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: Using a variable on next page before the if(isset statement

22/03/2023

Resolved: What is a difference between TextStyle.FULL and TextStyle.FULL_STANDALONE

22/03/2023

Resolved: How to access custom object in javascript module from another module?

22/03/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.