0

TDengine sql error when executing aggregate query:

select avg(value) as gauge from table1 where ts >= now - 30d and ts <= now group by cluster interval(30d)
DB error: syntax error near "interval(30d);" (0.000552s)

What are the syntax errors in this sql?

naissance
  • 36
  • 12

1 Answers1

0

Finally found in TDengine documentation: https://www.taosdata.com/docs/en/v2.0/taos-sql Listed the order of select conditional statements.

SELECT select_expr [, select_expr ...]
    FROM {tb_name_list}
    [WHERE where_condition]
    [SESSION(ts_col, tol_val)]
    [STATE_WINDOW(col)]
    [INTERVAL(interval_val [, interval_offset]) [SLIDING sliding_val]]
    [FILL(fill_mod_and_val)]
    [GROUP BY col_list]
    [ORDER BY col_list { DESC | ASC }]
    [SLIMIT limit_val [SOFFSET offset_val]]
    [LIMIT limit_val [OFFSET offset_val]]
    [>> export_file];

So the Group by should be put after Interval, here is the correct sql:

select avg(value) as gauge from table1 where ts >= now - 30d and ts <= now interval(30d) group by cluster
naissance
  • 36
  • 12