Skip to content
Advertisement

Get the average of values in every specific epoch ranges in unix timestamp which returns -1 in specific condition in MySQL

I have a MySQL table which has some records as follows:

I want to compute the average for every 10 epochs to see the following results:

I saw some similar answers like enter link description here and enter link description here and enter link description here but these answers are not a solution for my specific question. How can I get the above results?

Advertisement

Answer

The easiest way to do this is to use a calendar table. Consider this approach:

In practice, if you have the need to do this sort of query often, instead of the inline subquery labelled as cal above, you might want to have a full dedicated table representing all timestamp ranges.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement