I want to group data by time intervals and then count the number of records that meet specific conditions within the Table Model of Apache IoTDB 2.0.6. However, my query execution failed. Below are the specific steps I took:
1. Create Table and Insert Data
CREATE TABLE events (device_id STRING TAG, value FLOAT FIELD);
INSERT INTO events (`time`, device_id, value) VALUES
(1000, 'd1', 10.0),
(2000, 'd1', 20.0),
(3000, 'd1', 15.0),
(4000, 'd1', 25.0),
(5000, 'd1', 5.0);
2. Query Attempt 1: Using 's' unit
I tried to aggregate data using a 2-second time window and count occurrences where value > 15.
SELECT COUNT_IF(value > 15) as high_value_count FROM events `GROUP BY` `TIME`(2s);
Error Message:
Msg: org.apache.iotdb.jdbc.IoTDBSQLException: 700: line 1:77: mismatched input 's'. Expecting: ')', ','
3. Query Attempt 2: Using 'ms' unit
I tried using milliseconds instead.
SELECT COUNT_IF(value > 15) as high_value_count FROM events `GROUP BY` `TIME`(2000ms);
Error Message:
Msg: org.apache.iotdb.jdbc.IoTDBSQLException: 700: line 1:80: mismatched input 'ms'. Expecting: ')', ','
4. Query Attempt 3: Using numeric value only
I tried removing the time unit.
SELECT COUNT_IF(value > 15) as high_value_count FROM events `GROUP BY` `TIME`(2000);
Error Message:
Msg: org.apache.iotdb.jdbc.IoTDBSQLException: 701: Unknown function: time
Questions:
Does the Table Model support GROUP BY TIME? If so, what is the correct syntax?
How should the time interval be specified (e.g., 2s, 2000ms, or just 2000)?
If it is not supported in this way, how should I adjust my SQL query to execute successfully?