There is an interesting enough solution if you know the maximum time you have ever had. Create a table with all the numbers in it from one to the maximum time.
millisecond ----------- 1 2 3 ... 1240
Name it time_dimension (this method is often used when modeling sizes when storing data.)
Then this:
SELECT COUNT(*) FROM your_data INNER JOIN time_dimension ON time_dimension.millisecond BETWEEN your_data.start AND your_data.stop WHERE time_dimension.millisecond BETWEEN 1030 AND 1100
... will give you a total number of milliseconds of run time between 1030 and 1100.
Of course, whether you can use this method depends on whether you can safely predict the maximum number of milliseconds that will ever be in your data.
This is often used in a data warehouse, as I said; it fits well with some problems - for example, I used it for insurance systems where the total number of days between two dates was needed and where the total date range of the data could be easily estimated (from the earliest date of birth of the client to a date for several years in the future , for the end date of any policies being sold.)
It may not work for you, but I thought it was worth sharing as an interesting technique!
source share