Best way to get aggregates from ranged data
0
votes
2
answers
203
views
The problem I'm having is as follows:
I have 'shifts' table with the following ranged data I want to make aggregates on:
ID | started_at | ended_at | costs
1 | 2022-08-23 08:00 | 2022-08-23 11:00 | 150
2 | 2022-08-23 08:30 | 2022-08-23 09:30 | 50
Currently using MySQL, how to get the following data:
time | total_costs | total_count
2022-08-23 08:00 | 75 | 2
2022-08-23 09:00 | 75 | 2
2022-08-23 10:00 | 50 | 1
Or do you recommend using other DB specially built for this kind of data?
**Edit:** sorry for the inconvenience. Time is an interval 2022-08-23 08:00-09:00, 2022-08-23 09:00-10:00, and so on. So the
total_costs
are the sum(calculated_costs)
for the shifts that fall into the interval.
calculated_costs = (cost / total_duration) * duration_in_interval
(150 / 3 hours) * 1 hour = 50
total_count = the count(*) of shifts that have the started_at and ended_at in/around the current time (interval)
Hope someone kan point me in the right direction. Thanks!
Asked by Matt_45
(1 rep)
Aug 23, 2022, 08:18 AM
Last activity: Aug 24, 2022, 07:02 AM
Last activity: Aug 24, 2022, 07:02 AM