Skip to content
Advertisement

How to fill missing values in aggregate-by-time function

I have function (from this question) which groups values by every 5 minutes and calculate min/avg/max:

However, due to missing values, some five-minute periods are skipped, making the timeline inconsistent. How to make it so that in the absence of data for a certain period, the value of max / avg / min becomes 0, instead of being skipped?

For example:

If I have timestamp – value

  • 1200000001 – 100
  • 1200000002 – 300
  • 1200000301 – 100
  • 1200000601 – 300
I want to get this: (select min/avg/max, time between 1200000000 and 1200001200)
  • 1200000000 – 100/200/300
  • 1200000300 – 100/100/100
  • 1200000600 – 300/300/300
  • 1200000900 – 0/0/0
Instead of this: (time between 1200000000 and 1200001200)
  • 1200000000 – 100/200/300
  • 1200000300 – 100/100/100
  • 1200000600 – 300/300/300
  • 1200000900 – THIS LINE WILL NOT BE, I will only get 3 lines above. No data between 1200000900 and 1200001200 for calculation.

My Answer:

Generate first table with required time range, and then left join this generated table on query with common group by operator. Such like this:

Advertisement

Answer

Alternative answer is generate first table with required time range, and then left join this generated table on query with common group by operator.

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