I have the following table
id score start_time end_time
1 60 25 30
2 85 5 10
3 90 10 15
4 100 0 20
I would like to perform the query
SELECT * FROM table
WHERE the range between start_time and end_time doesn't overlap with anything in the result set ordered by score DESC
So in this case the result set would be:
id score start_time end_time
4 100 0 20
1 60 25 30
since the range between start_time and end_time for table.id =2 and table.id =3 overlapped with the range between start_time and end_time for table.id =4 and the score of table.id =4 was greater than the score of table.id =2 and table.id =3
Is it possible to do this strictly through mysql?
EDIT: Sorry, had a minor mistake in there. Now it really works.
Set up test data:
The function which is needed:
How to use the function:
P.S: Really nice question. Was fun to solve