Sample Header Ad - 728x90

Possible to GROUP BY across different columns in mariadb/mysql

0 votes
1 answer
381 views
I have a table full of events similar to this:
date     | start_time | end_time | length 
--------------------------------------------
2022-01-10 | 07:00:00   | 16:00:00 |      9
2022-01-11 | 07:00:00   | 16:00:00 |      9
2022-01-11 | 16:00:00   | 20:00:00 |      5
2022-01-12 | 07:00:00   | 12:00:00 |      5
2022-01-12 | 16:00:00   | 20:00:00 |      5
I want to group by contiguous events on each date. See how on 2022-01-11 there are two entries, one ending at the same time the next one starts? (but not on 12th) I'd like to get something like this:
select date, SUM(length) from events
group by date, ????

date     | length
--------------------
2022-01-10 |      9
2022-01-11 |     14
2022-01-12 |      5
2022-01-12 |      5
Is this even possible?
Asked by MrWainscotting (1 rep)
Jan 7, 2022, 12:36 AM
Last activity: Jan 12, 2025, 07:07 AM