Search code examples
time-seriestdengine

question about TDengine aggregation usage


I'm using TDengine for data processing. Is there someone know how to do aggregation by fixed step, not by time window?

original data

           ts            |         val         |
======================================================
 2021-04-12 17:31:00.000 |              5.89000 |
 2021-04-12 17:32:00.000 |              5.86000 |
 2021-04-12 17:33:00.000 |              5.85000 |
 2021-04-12 17:34:00.000 |              5.84000 |
 2021-04-12 17:35:00.000 |              5.82000 |
 2021-04-12 17:36:00.000 |              5.84000 |
 2021-04-12 17:37:00.000 |              5.83000 |
 2021-04-12 17:38:00.000 |              5.83000 |
 2021-04-12 17:39:00.000 |              5.84000 |
 2021-04-12 17:40:00.000 |              5.84000 |
 2021-04-12 17:41:00.000 |              5.84000 |
 2021-04-12 17:42:00.000 |              5.85000 |
 2021-04-12 17:43:00.000 |              5.84000 |
 2021-04-12 17:44:00.000 |              5.85000 |

such as sum(val) by step 5,expected

 2021-04-12 17:35:00.000 29.26
 2021-04-12 17:40:00.000 29.18
 2021-04-12 17:44:00.000 29.18

thanks,


Solution

  • You can use INTERVAl and SlIDING functions to aggregation. Documents: https://www.taosdata.com/en/documentation/taos-sql#functions