I have saved some data in 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');
There is something puzzled while I'm trying to get the total data amount of one sensor, here are SQLs that I've tried:
-- 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 |
+-------+---------------------+