我已经在cnosdb中保存了一些数据:
CREATE TABLE table_1(temp DOUBLE, fan BIGINT, TAGS(ta, tb));
INSERT INTO table_1(time, temp, fan, ta, tb) VALUES
('2024-01-01T00:00:00', 70, 0, 'a1', 'b1'),
('2024-01-01T00:00:00', 71, 0, 'a2', 'b2'),
('2024-01-01T00:01:00', 70, 0, 'a1', 'b1'),
('2024-01-01T00:01:00', 71, 0, 'a2', 'b2');
在尝试获取一个传感器的总数据量时,有一些困惑,以下是我尝试过的 SQL:
-- Select `count(*)` returns unexpected value if there are only tag column filters.
SELECT COUNT(*) AS total FROM table_1 WHERE ta = 'a1' and tb = 'b1';
+-------+
| total |
+-------+
| 1 |
+-------+
-- I can get the expected result if there are field column filters in the sql.
SELECT COUNT(*) AS total FROM table_1 WHERE ta = 'a1' and tb = 'b1' and time > 0;
+-------+
| total |
+-------+
| 2 |
+-------+
-- I can get the expected result if there are more selections in the sql.
SELECT COUNT(*) AS total, MIN(time) as min_time FROM table_1 WHERE ta = 'a1' and tb = 'b1';
+-------+---------------------+
| total | min_time |
+-------+---------------------+
| 2 | 2024-01-01T00:00:00 |
+-------+---------------------+
目前计数功能存在一些错误。如果你想得到总数,count函数中的参数现在应该是field而不是tag。